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 | |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame^] | 16 | #include "clang/Sema/Sema.h" |
| 17 | #include "clang/Sema/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. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 279 | DeclarationNameInfo |
| 280 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 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, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 471 | bool Variadic, unsigned Quals, |
| 472 | const FunctionType::ExtInfo &Info); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 473 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 474 | /// \brief Build a new unprototyped function type. |
| 475 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 476 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 477 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 478 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 479 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 480 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 481 | /// \brief Build a new typedef type. |
| 482 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 483 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 484 | } |
| 485 | |
| 486 | /// \brief Build a new class/struct/union type. |
| 487 | QualType RebuildRecordType(RecordDecl *Record) { |
| 488 | return SemaRef.Context.getTypeDeclType(Record); |
| 489 | } |
| 490 | |
| 491 | /// \brief Build a new Enum type. |
| 492 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 493 | return SemaRef.Context.getTypeDeclType(Enum); |
| 494 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 495 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 497 | /// |
| 498 | /// By default, performs semantic analysis when building the typeof type. |
| 499 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 500 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 503 | /// |
| 504 | /// By default, builds a new TypeOfType with the given underlying type. |
| 505 | QualType RebuildTypeOfType(QualType Underlying); |
| 506 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 508 | /// |
| 509 | /// By default, performs semantic analysis when building the decltype type. |
| 510 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 511 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 513 | /// \brief Build a new template specialization type. |
| 514 | /// |
| 515 | /// By default, performs semantic analysis when building the template |
| 516 | /// specialization type. Subclasses may override this routine to provide |
| 517 | /// different behavior. |
| 518 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 519 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 520 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 522 | /// \brief Build a new qualified name type. |
| 523 | /// |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 524 | /// By default, builds a new ElaboratedType type from the keyword, |
| 525 | /// the nested-name-specifier and the named type. |
| 526 | /// Subclasses may override this routine to provide different behavior. |
| 527 | QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword, |
| 528 | NestedNameSpecifier *NNS, QualType Named) { |
| 529 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | |
| 532 | /// \brief Build a new typename type that refers to a template-id. |
| 533 | /// |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 534 | /// By default, builds a new DependentNameType type from the |
| 535 | /// nested-name-specifier and the given type. Subclasses may override |
| 536 | /// this routine to provide different behavior. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 537 | QualType RebuildDependentTemplateSpecializationType( |
| 538 | ElaboratedTypeKeyword Keyword, |
| 539 | NestedNameSpecifier *NNS, |
| 540 | const IdentifierInfo *Name, |
| 541 | SourceLocation NameLoc, |
| 542 | const TemplateArgumentListInfo &Args) { |
| 543 | // Rebuild the template name. |
| 544 | // TODO: avoid TemplateName abstraction |
| 545 | TemplateName InstName = |
| 546 | getDerived().RebuildTemplateName(NNS, *Name, QualType()); |
| 547 | |
Douglas Gregor | 96fb42e | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 548 | if (InstName.isNull()) |
| 549 | return QualType(); |
| 550 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 551 | // If it's still dependent, make a dependent specialization. |
| 552 | if (InstName.getAsDependentTemplateName()) |
| 553 | return SemaRef.Context.getDependentTemplateSpecializationType( |
| 554 | Keyword, NNS, Name, Args); |
| 555 | |
| 556 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 557 | // specialization. |
| 558 | QualType T = |
| 559 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 560 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 561 | |
Abramo Bagnara | 22f638a | 2010-08-10 13:46:45 +0000 | [diff] [blame] | 562 | // NOTE: NNS is already recorded in template specialization type T. |
| 563 | return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 565 | |
| 566 | /// \brief Build a new typename type that refers to an identifier. |
| 567 | /// |
| 568 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 569 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 570 | /// different behavior. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 571 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 572 | NestedNameSpecifier *NNS, |
| 573 | const IdentifierInfo *Id, |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 574 | SourceLocation KeywordLoc, |
| 575 | SourceRange NNSRange, |
| 576 | SourceLocation IdLoc) { |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 577 | CXXScopeSpec SS; |
| 578 | SS.setScopeRep(NNS); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 579 | SS.setRange(NNSRange); |
| 580 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 581 | if (NNS->isDependent()) { |
| 582 | // If the name is still dependent, just build a new dependent name type. |
| 583 | if (!SemaRef.computeDeclContext(SS)) |
| 584 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 585 | } |
| 586 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 587 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 588 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, |
| 589 | KeywordLoc, NNSRange, IdLoc); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 590 | |
| 591 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 592 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 593 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 594 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 595 | // referring to. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 596 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 597 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 598 | if (!DC) |
| 599 | return QualType(); |
| 600 | |
John McCall | 5613876 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 601 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 602 | return QualType(); |
| 603 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 604 | TagDecl *Tag = 0; |
| 605 | SemaRef.LookupQualifiedName(Result, DC); |
| 606 | switch (Result.getResultKind()) { |
| 607 | case LookupResult::NotFound: |
| 608 | case LookupResult::NotFoundInCurrentInstantiation: |
| 609 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 611 | case LookupResult::Found: |
| 612 | Tag = Result.getAsSingle<TagDecl>(); |
| 613 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 614 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 615 | case LookupResult::FoundOverloaded: |
| 616 | case LookupResult::FoundUnresolvedValue: |
| 617 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 618 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 620 | case LookupResult::Ambiguous: |
| 621 | // Let the LookupResult structure handle ambiguities. |
| 622 | return QualType(); |
| 623 | } |
| 624 | |
| 625 | if (!Tag) { |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 626 | // FIXME: Would be nice to highlight just the source range. |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 627 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Douglas Gregor | 1eabb7d | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 628 | << Kind << Id << DC; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 629 | return QualType(); |
| 630 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 631 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 632 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 633 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | 4033642 | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 634 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 635 | return QualType(); |
| 636 | } |
| 637 | |
| 638 | // Build the elaborated-type-specifier type. |
| 639 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 640 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 643 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 644 | /// identifier that names the next step in the nested-name-specifier. |
| 645 | /// |
| 646 | /// By default, performs semantic analysis when building the new |
| 647 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 648 | /// different behavior. |
| 649 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 650 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 651 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 652 | QualType ObjectType, |
| 653 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 654 | |
| 655 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 656 | /// namespace named in the next step in the nested-name-specifier. |
| 657 | /// |
| 658 | /// By default, performs semantic analysis when building the new |
| 659 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 660 | /// different behavior. |
| 661 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 662 | SourceRange Range, |
| 663 | NamespaceDecl *NS); |
| 664 | |
| 665 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 666 | /// type named in the next step in the nested-name-specifier. |
| 667 | /// |
| 668 | /// By default, performs semantic analysis when building the new |
| 669 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 670 | /// different behavior. |
| 671 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 672 | SourceRange Range, |
| 673 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 674 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 675 | |
| 676 | /// \brief Build a new template name given a nested name specifier, a flag |
| 677 | /// indicating whether the "template" keyword was provided, and the template |
| 678 | /// that the template name refers to. |
| 679 | /// |
| 680 | /// By default, builds the new template name directly. Subclasses may override |
| 681 | /// this routine to provide different behavior. |
| 682 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 683 | bool TemplateKW, |
| 684 | TemplateDecl *Template); |
| 685 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 686 | /// \brief Build a new template name given a nested name specifier and the |
| 687 | /// name that is referred to as a template. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis to determine whether the name can |
| 690 | /// be resolved to a specific template, then builds the appropriate kind of |
| 691 | /// template name. Subclasses may override this routine to provide different |
| 692 | /// behavior. |
| 693 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 694 | const IdentifierInfo &II, |
| 695 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 697 | /// \brief Build a new template name given a nested name specifier and the |
| 698 | /// overloaded operator name that is referred to as a template. |
| 699 | /// |
| 700 | /// By default, performs semantic analysis to determine whether the name can |
| 701 | /// be resolved to a specific template, then builds the appropriate kind of |
| 702 | /// template name. Subclasses may override this routine to provide different |
| 703 | /// behavior. |
| 704 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 705 | OverloadedOperatorKind Operator, |
| 706 | QualType ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 707 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 708 | /// \brief Build a new compound statement. |
| 709 | /// |
| 710 | /// By default, performs semantic analysis to build the new statement. |
| 711 | /// Subclasses may override this routine to provide different behavior. |
| 712 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 713 | MultiStmtArg Statements, |
| 714 | SourceLocation RBraceLoc, |
| 715 | bool IsStmtExpr) { |
| 716 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 717 | IsStmtExpr); |
| 718 | } |
| 719 | |
| 720 | /// \brief Build a new case statement. |
| 721 | /// |
| 722 | /// By default, performs semantic analysis to build the new statement. |
| 723 | /// Subclasses may override this routine to provide different behavior. |
| 724 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 725 | ExprArg LHS, |
| 726 | SourceLocation EllipsisLoc, |
| 727 | ExprArg RHS, |
| 728 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 730 | ColonLoc); |
| 731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | /// \brief Attach the body to a new case statement. |
| 734 | /// |
| 735 | /// By default, performs semantic analysis to build the new statement. |
| 736 | /// Subclasses may override this routine to provide different behavior. |
| 737 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 738 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 739 | return move(S); |
| 740 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 742 | /// \brief Build a new default statement. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis to build the new statement. |
| 745 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | SourceLocation ColonLoc, |
| 748 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 750 | /*CurScope=*/0); |
| 751 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 753 | /// \brief Build a new label statement. |
| 754 | /// |
| 755 | /// By default, performs semantic analysis to build the new statement. |
| 756 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | IdentifierInfo *Id, |
| 759 | SourceLocation ColonLoc, |
| 760 | StmtArg SubStmt) { |
| 761 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 762 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 764 | /// \brief Build a new "if" statement. |
| 765 | /// |
| 766 | /// By default, performs semantic analysis to build the new statement. |
| 767 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 768 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 769 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 770 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 771 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 772 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 773 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 775 | /// \brief Start building a new switch statement. |
| 776 | /// |
| 777 | /// By default, performs semantic analysis to build the new statement. |
| 778 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 779 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 780 | Sema::ExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 781 | VarDecl *CondVar) { |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 782 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 783 | DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 784 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 786 | /// \brief Attach the body to the switch statement. |
| 787 | /// |
| 788 | /// By default, performs semantic analysis to build the new statement. |
| 789 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 791 | StmtArg Switch, StmtArg Body) { |
| 792 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 793 | move(Body)); |
| 794 | } |
| 795 | |
| 796 | /// \brief Build a new while statement. |
| 797 | /// |
| 798 | /// By default, performs semantic analysis to build the new statement. |
| 799 | /// Subclasses may override this routine to provide different behavior. |
| 800 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 801 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 802 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 803 | StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 804 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 805 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 808 | /// \brief Build a new do-while statement. |
| 809 | /// |
| 810 | /// By default, performs semantic analysis to build the new statement. |
| 811 | /// Subclasses may override this routine to provide different behavior. |
| 812 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 813 | SourceLocation WhileLoc, |
| 814 | SourceLocation LParenLoc, |
| 815 | ExprArg Cond, |
| 816 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | move(Cond), RParenLoc); |
| 819 | } |
| 820 | |
| 821 | /// \brief Build a new for statement. |
| 822 | /// |
| 823 | /// By default, performs semantic analysis to build the new statement. |
| 824 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 826 | SourceLocation LParenLoc, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 827 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 828 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 829 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 830 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 831 | DeclPtrTy::make(CondVar), |
| 832 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 833 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 834 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 835 | /// \brief Build a new goto statement. |
| 836 | /// |
| 837 | /// By default, performs semantic analysis to build the new statement. |
| 838 | /// Subclasses may override this routine to provide different behavior. |
| 839 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 840 | SourceLocation LabelLoc, |
| 841 | LabelStmt *Label) { |
| 842 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 843 | } |
| 844 | |
| 845 | /// \brief Build a new indirect goto statement. |
| 846 | /// |
| 847 | /// By default, performs semantic analysis to build the new statement. |
| 848 | /// Subclasses may override this routine to provide different behavior. |
| 849 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 850 | SourceLocation StarLoc, |
| 851 | ExprArg Target) { |
| 852 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 853 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 855 | /// \brief Build a new return statement. |
| 856 | /// |
| 857 | /// By default, performs semantic analysis to build the new statement. |
| 858 | /// Subclasses may override this routine to provide different behavior. |
| 859 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 860 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 861 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 862 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 863 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 864 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 865 | /// \brief Build a new declaration statement. |
| 866 | /// |
| 867 | /// By default, performs semantic analysis to build the new statement. |
| 868 | /// Subclasses may override this routine to provide different behavior. |
| 869 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 871 | SourceLocation EndLoc) { |
| 872 | return getSema().Owned( |
| 873 | new (getSema().Context) DeclStmt( |
| 874 | DeclGroupRef::Create(getSema().Context, |
| 875 | Decls, NumDecls), |
| 876 | StartLoc, EndLoc)); |
| 877 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 878 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 879 | /// \brief Build a new inline asm statement. |
| 880 | /// |
| 881 | /// By default, performs semantic analysis to build the new statement. |
| 882 | /// Subclasses may override this routine to provide different behavior. |
| 883 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 884 | bool IsSimple, |
| 885 | bool IsVolatile, |
| 886 | unsigned NumOutputs, |
| 887 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 888 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 889 | MultiExprArg Constraints, |
| 890 | MultiExprArg Exprs, |
| 891 | ExprArg AsmString, |
| 892 | MultiExprArg Clobbers, |
| 893 | SourceLocation RParenLoc, |
| 894 | bool MSAsm) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 895 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 896 | NumInputs, Names, move(Constraints), |
| 897 | move(Exprs), move(AsmString), move(Clobbers), |
| 898 | RParenLoc, MSAsm); |
| 899 | } |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 900 | |
| 901 | /// \brief Build a new Objective-C @try statement. |
| 902 | /// |
| 903 | /// By default, performs semantic analysis to build the new statement. |
| 904 | /// Subclasses may override this routine to provide different behavior. |
| 905 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 906 | StmtArg TryBody, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 907 | MultiStmtArg CatchStmts, |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 908 | StmtArg Finally) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 909 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 910 | move(Finally)); |
| 911 | } |
| 912 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 913 | /// \brief Rebuild an Objective-C exception declaration. |
| 914 | /// |
| 915 | /// By default, performs semantic analysis to build the new declaration. |
| 916 | /// Subclasses may override this routine to provide different behavior. |
| 917 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 918 | TypeSourceInfo *TInfo, QualType T) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 919 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 920 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 921 | ExceptionDecl->getLocation()); |
| 922 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 923 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 924 | /// \brief Build a new Objective-C @catch statement. |
| 925 | /// |
| 926 | /// By default, performs semantic analysis to build the new statement. |
| 927 | /// Subclasses may override this routine to provide different behavior. |
| 928 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 929 | SourceLocation RParenLoc, |
| 930 | VarDecl *Var, |
| 931 | StmtArg Body) { |
| 932 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 933 | Sema::DeclPtrTy::make(Var), |
| 934 | move(Body)); |
| 935 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 937 | /// \brief Build a new Objective-C @finally statement. |
| 938 | /// |
| 939 | /// By default, performs semantic analysis to build the new statement. |
| 940 | /// Subclasses may override this routine to provide different behavior. |
| 941 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 942 | StmtArg Body) { |
| 943 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 944 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 945 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 946 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 947 | /// |
| 948 | /// By default, performs semantic analysis to build the new statement. |
| 949 | /// Subclasses may override this routine to provide different behavior. |
| 950 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 951 | ExprArg Operand) { |
| 952 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 953 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 955 | /// \brief Build a new Objective-C @synchronized statement. |
| 956 | /// |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 957 | /// By default, performs semantic analysis to build the new statement. |
| 958 | /// Subclasses may override this routine to provide different behavior. |
| 959 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 960 | ExprArg Object, |
| 961 | StmtArg Body) { |
| 962 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 963 | move(Body)); |
| 964 | } |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 965 | |
| 966 | /// \brief Build a new Objective-C fast enumeration statement. |
| 967 | /// |
| 968 | /// By default, performs semantic analysis to build the new statement. |
| 969 | /// Subclasses may override this routine to provide different behavior. |
| 970 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 971 | SourceLocation LParenLoc, |
| 972 | StmtArg Element, |
| 973 | ExprArg Collection, |
| 974 | SourceLocation RParenLoc, |
| 975 | StmtArg Body) { |
| 976 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 977 | move(Element), |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 978 | move(Collection), |
| 979 | RParenLoc, |
| 980 | move(Body)); |
| 981 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 983 | /// \brief Build a new C++ exception declaration. |
| 984 | /// |
| 985 | /// By default, performs semantic analysis to build the new decaration. |
| 986 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 988 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 989 | IdentifierInfo *Name, |
| 990 | SourceLocation Loc, |
| 991 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 993 | TypeRange); |
| 994 | } |
| 995 | |
| 996 | /// \brief Build a new C++ catch statement. |
| 997 | /// |
| 998 | /// By default, performs semantic analysis to build the new statement. |
| 999 | /// Subclasses may override this routine to provide different behavior. |
| 1000 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 1001 | VarDecl *ExceptionDecl, |
| 1002 | StmtArg Handler) { |
| 1003 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1005 | Handler.takeAs<Stmt>())); |
| 1006 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1008 | /// \brief Build a new C++ try statement. |
| 1009 | /// |
| 1010 | /// By default, performs semantic analysis to build the new statement. |
| 1011 | /// Subclasses may override this routine to provide different behavior. |
| 1012 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1013 | StmtArg TryBlock, |
| 1014 | MultiStmtArg Handlers) { |
| 1015 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1018 | /// \brief Build a new expression that references a declaration. |
| 1019 | /// |
| 1020 | /// By default, performs semantic analysis to build the new expression. |
| 1021 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1022 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1023 | LookupResult &R, |
| 1024 | bool RequiresADL) { |
| 1025 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | /// \brief Build a new expression that references a declaration. |
| 1030 | /// |
| 1031 | /// By default, performs semantic analysis to build the new expression. |
| 1032 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1033 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1034 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1035 | ValueDecl *VD, |
| 1036 | const DeclarationNameInfo &NameInfo, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1037 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1038 | CXXScopeSpec SS; |
| 1039 | SS.setScopeRep(Qualifier); |
| 1040 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1041 | |
| 1042 | // FIXME: loses template args. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1043 | |
| 1044 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// By default, performs semantic analysis to build the new expression. |
| 1050 | /// Subclasses may override this routine to provide different behavior. |
| 1051 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1052 | SourceLocation RParen) { |
| 1053 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1054 | } |
| 1055 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1056 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1058 | /// By default, performs semantic analysis to build the new expression. |
| 1059 | /// Subclasses may override this routine to provide different behavior. |
| 1060 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1061 | SourceLocation OperatorLoc, |
| 1062 | bool isArrow, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1063 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1064 | SourceRange QualifierRange, |
| 1065 | TypeSourceInfo *ScopeType, |
| 1066 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1067 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1068 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1072 | /// By default, performs semantic analysis to build the new expression. |
| 1073 | /// Subclasses may override this routine to provide different behavior. |
| 1074 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1075 | UnaryOperator::Opcode Opc, |
| 1076 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1077 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1080 | /// \brief Build a new builtin offsetof expression. |
| 1081 | /// |
| 1082 | /// By default, performs semantic analysis to build the new expression. |
| 1083 | /// Subclasses may override this routine to provide different behavior. |
| 1084 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1085 | TypeSourceInfo *Type, |
| 1086 | Action::OffsetOfComponent *Components, |
| 1087 | unsigned NumComponents, |
| 1088 | SourceLocation RParenLoc) { |
| 1089 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1090 | NumComponents, RParenLoc); |
| 1091 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1095 | /// By default, performs semantic analysis to build the new expression. |
| 1096 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1097 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1098 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1100 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1106 | /// By default, performs semantic analysis to build the new expression. |
| 1107 | /// Subclasses may override this routine to provide different behavior. |
| 1108 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1109 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1110 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1111 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1112 | OpLoc, isSizeOf, R); |
| 1113 | if (Result.isInvalid()) |
| 1114 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1116 | SubExpr.release(); |
| 1117 | return move(Result); |
| 1118 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | /// By default, performs semantic analysis to build the new expression. |
| 1123 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | SourceLocation LBracketLoc, |
| 1126 | ExprArg RHS, |
| 1127 | SourceLocation RBracketLoc) { |
| 1128 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | RBracketLoc); |
| 1131 | } |
| 1132 | |
| 1133 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1134 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1135 | /// By default, performs semantic analysis to build the new expression. |
| 1136 | /// Subclasses may override this routine to provide different behavior. |
| 1137 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1138 | MultiExprArg Args, |
| 1139 | SourceLocation *CommaLocs, |
| 1140 | SourceLocation RParenLoc) { |
| 1141 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1142 | move(Args), CommaLocs, RParenLoc); |
| 1143 | } |
| 1144 | |
| 1145 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1147 | /// By default, performs semantic analysis to build the new expression. |
| 1148 | /// Subclasses may override this routine to provide different behavior. |
| 1149 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1151 | NestedNameSpecifier *Qualifier, |
| 1152 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1153 | const DeclarationNameInfo &MemberNameInfo, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1154 | ValueDecl *Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1155 | NamedDecl *FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1156 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1157 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1158 | if (!Member->getDeclName()) { |
| 1159 | // We have a reference to an unnamed field. |
| 1160 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1162 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1163 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1164 | FoundDecl, Member)) |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1165 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1166 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1168 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1169 | Member, MemberNameInfo, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1170 | cast<FieldDecl>(Member)->getType()); |
| 1171 | return getSema().Owned(ME); |
| 1172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1174 | CXXScopeSpec SS; |
| 1175 | if (Qualifier) { |
| 1176 | SS.setRange(QualifierRange); |
| 1177 | SS.setScopeRep(Qualifier); |
| 1178 | } |
| 1179 | |
Douglas Gregor | 83c9abc | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1180 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 1181 | getSema().DefaultFunctionArrayConversion(BaseExpr); |
| 1182 | QualType BaseType = BaseExpr->getType(); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1183 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1184 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1185 | // cases; we should avoid this when possible. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1186 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1187 | R.addDecl(FoundDecl); |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1188 | R.resolveKind(); |
| 1189 | |
Douglas Gregor | 83c9abc | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1190 | return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr), |
| 1191 | BaseType, OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1192 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1193 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | } |
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 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1198 | /// By default, performs semantic analysis to build the new expression. |
| 1199 | /// Subclasses may override this routine to provide different behavior. |
| 1200 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1201 | BinaryOperator::Opcode Opc, |
| 1202 | ExprArg LHS, ExprArg RHS) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1203 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1204 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1208 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1209 | /// By default, performs semantic analysis to build the new expression. |
| 1210 | /// Subclasses may override this routine to provide different behavior. |
| 1211 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1212 | SourceLocation QuestionLoc, |
| 1213 | ExprArg LHS, |
| 1214 | SourceLocation ColonLoc, |
| 1215 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | move(LHS), move(RHS)); |
| 1218 | } |
| 1219 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | /// By default, performs semantic analysis to build the new expression. |
| 1223 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1224 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1225 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | SourceLocation RParenLoc, |
| 1227 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1228 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1229 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | } |
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 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1233 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1234 | /// By default, performs semantic analysis to build the new expression. |
| 1235 | /// Subclasses may override this routine to provide different behavior. |
| 1236 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1237 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | SourceLocation RParenLoc, |
| 1239 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1240 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1241 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | } |
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 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1246 | /// By default, performs semantic analysis to build the new expression. |
| 1247 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1248 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1249 | SourceLocation OpLoc, |
| 1250 | SourceLocation AccessorLoc, |
| 1251 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1252 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1253 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1254 | QualType BaseType = ((Expr*) Base.get())->getType(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1255 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1256 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1257 | OpLoc, /*IsArrow*/ false, |
| 1258 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1259 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1260 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | } |
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 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1265 | /// By default, performs semantic analysis to build the new expression. |
| 1266 | /// Subclasses may override this routine to provide different behavior. |
| 1267 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1268 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1269 | SourceLocation RBraceLoc, |
| 1270 | QualType ResultTy) { |
| 1271 | OwningExprResult Result |
| 1272 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1273 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1274 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1275 | |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1276 | // Patch in the result type we were given, which may have been computed |
| 1277 | // when the initial InitListExpr was built. |
| 1278 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1279 | ILE->setType(ResultTy); |
| 1280 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1281 | } |
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 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1285 | /// By default, performs semantic analysis to build the new expression. |
| 1286 | /// Subclasses may override this routine to provide different behavior. |
| 1287 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1288 | MultiExprArg ArrayExprs, |
| 1289 | SourceLocation EqualOrColonLoc, |
| 1290 | bool GNUSyntax, |
| 1291 | ExprArg Init) { |
| 1292 | OwningExprResult Result |
| 1293 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1294 | move(Init)); |
| 1295 | if (Result.isInvalid()) |
| 1296 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1298 | ArrayExprs.release(); |
| 1299 | return move(Result); |
| 1300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1302 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | /// By default, builds the implicit value initialization without performing |
| 1305 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1306 | /// different behavior. |
| 1307 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1308 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1309 | } |
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 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | /// By default, performs semantic analysis to build the new expression. |
| 1314 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1315 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| 1316 | ExprArg SubExpr, TypeSourceInfo *TInfo, |
| 1317 | SourceLocation RParenLoc) { |
| 1318 | return getSema().BuildVAArgExpr(BuiltinLoc, |
| 1319 | move(SubExpr), TInfo, |
| 1320 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1324 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1325 | /// By default, performs semantic analysis to build the new expression. |
| 1326 | /// Subclasses may override this routine to provide different behavior. |
| 1327 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1328 | MultiExprArg SubExprs, |
| 1329 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1330 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1331 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | /// |
| 1336 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | /// rather than attempting to map the label statement itself. |
| 1338 | /// Subclasses may override this routine to provide different behavior. |
| 1339 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1340 | SourceLocation LabelLoc, |
| 1341 | LabelStmt *Label) { |
| 1342 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1343 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1345 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | /// By default, performs semantic analysis to build the new expression. |
| 1348 | /// Subclasses may override this routine to provide different behavior. |
| 1349 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1350 | StmtArg SubStmt, |
| 1351 | SourceLocation RParenLoc) { |
| 1352 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1356 | /// |
| 1357 | /// By default, performs semantic analysis to build the new expression. |
| 1358 | /// Subclasses may override this routine to provide different behavior. |
| 1359 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Abramo Bagnara | 3fcb73d | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 1360 | TypeSourceInfo *TInfo1, |
| 1361 | TypeSourceInfo *TInfo2, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1362 | SourceLocation RParenLoc) { |
Abramo Bagnara | 3fcb73d | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 1363 | return getSema().BuildTypesCompatibleExpr(BuiltinLoc, |
| 1364 | TInfo1, TInfo2, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | RParenLoc); |
| 1366 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | /// \brief Build a new __builtin_choose_expr expression. |
| 1369 | /// |
| 1370 | /// By default, performs semantic analysis to build the new expression. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
| 1372 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1373 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1374 | SourceLocation RParenLoc) { |
| 1375 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1376 | move(Cond), move(LHS), move(RHS), |
| 1377 | RParenLoc); |
| 1378 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | /// \brief Build a new overloaded operator call expression. |
| 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new expression. |
| 1383 | /// The semantic analysis provides the behavior of template instantiation, |
| 1384 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1387 | /// provide different behavior. |
| 1388 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1389 | SourceLocation OpLoc, |
| 1390 | ExprArg Callee, |
| 1391 | ExprArg First, |
| 1392 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
| 1394 | /// \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] | 1395 | /// reinterpret_cast. |
| 1396 | /// |
| 1397 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// Subclasses may override this routine to provide different behavior. |
| 1400 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1401 | Stmt::StmtClass Class, |
| 1402 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1403 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | SourceLocation RAngleLoc, |
| 1405 | SourceLocation LParenLoc, |
| 1406 | ExprArg SubExpr, |
| 1407 | SourceLocation RParenLoc) { |
| 1408 | switch (Class) { |
| 1409 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1410 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | move(SubExpr), RParenLoc); |
| 1413 | |
| 1414 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1415 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1419 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1420 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | RAngleLoc, LParenLoc, |
| 1422 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1426 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | default: |
| 1431 | assert(false && "Invalid C++ named cast"); |
| 1432 | break; |
| 1433 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1435 | return getSema().ExprError(); |
| 1436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | /// \brief Build a new C++ static_cast expression. |
| 1439 | /// |
| 1440 | /// By default, performs semantic analysis to build the new expression. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
| 1442 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1443 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1444 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1445 | SourceLocation RAngleLoc, |
| 1446 | SourceLocation LParenLoc, |
| 1447 | ExprArg SubExpr, |
| 1448 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1449 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1450 | TInfo, move(SubExpr), |
| 1451 | SourceRange(LAngleLoc, RAngleLoc), |
| 1452 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | /// \brief Build a new C++ dynamic_cast expression. |
| 1456 | /// |
| 1457 | /// By default, performs semantic analysis to build the new expression. |
| 1458 | /// Subclasses may override this routine to provide different behavior. |
| 1459 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1460 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1461 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | SourceLocation RAngleLoc, |
| 1463 | SourceLocation LParenLoc, |
| 1464 | ExprArg SubExpr, |
| 1465 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1466 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1467 | TInfo, move(SubExpr), |
| 1468 | SourceRange(LAngleLoc, RAngleLoc), |
| 1469 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1473 | /// |
| 1474 | /// By default, performs semantic analysis to build the new expression. |
| 1475 | /// Subclasses may override this routine to provide different behavior. |
| 1476 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1477 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1478 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1479 | SourceLocation RAngleLoc, |
| 1480 | SourceLocation LParenLoc, |
| 1481 | ExprArg SubExpr, |
| 1482 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1483 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1484 | TInfo, move(SubExpr), |
| 1485 | SourceRange(LAngleLoc, RAngleLoc), |
| 1486 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /// \brief Build a new C++ const_cast expression. |
| 1490 | /// |
| 1491 | /// By default, performs semantic analysis to build the new expression. |
| 1492 | /// Subclasses may override this routine to provide different behavior. |
| 1493 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1494 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1495 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | SourceLocation RAngleLoc, |
| 1497 | SourceLocation LParenLoc, |
| 1498 | ExprArg SubExpr, |
| 1499 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1500 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1501 | TInfo, move(SubExpr), |
| 1502 | SourceRange(LAngleLoc, RAngleLoc), |
| 1503 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1505 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | /// \brief Build a new C++ functional-style cast expression. |
| 1507 | /// |
| 1508 | /// By default, performs semantic analysis to build the new expression. |
| 1509 | /// Subclasses may override this routine to provide different behavior. |
| 1510 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1511 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | SourceLocation LParenLoc, |
| 1513 | ExprArg SubExpr, |
| 1514 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1515 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1517 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1519 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1520 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | RParenLoc); |
| 1522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1524 | /// \brief Build a new C++ typeid(type) expression. |
| 1525 | /// |
| 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1528 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1529 | SourceLocation TypeidLoc, |
| 1530 | TypeSourceInfo *Operand, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | SourceLocation RParenLoc) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1532 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1533 | RParenLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1536 | /// \brief Build a new C++ typeid(expr) expression. |
| 1537 | /// |
| 1538 | /// By default, performs semantic analysis to build the new expression. |
| 1539 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1540 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1541 | SourceLocation TypeidLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1542 | ExprArg Operand, |
| 1543 | SourceLocation RParenLoc) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1544 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1545 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | /// \brief Build a new C++ "this" expression. |
| 1549 | /// |
| 1550 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1551 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1553 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1554 | QualType ThisType, |
| 1555 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1556 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1557 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1558 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | /// \brief Build a new C++ throw expression. |
| 1562 | /// |
| 1563 | /// By default, performs semantic analysis to build the new expression. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
| 1565 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1566 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1567 | } |
| 1568 | |
| 1569 | /// \brief Build a new C++ default-argument expression. |
| 1570 | /// |
| 1571 | /// By default, builds a new default-argument expression, which does not |
| 1572 | /// require any semantic analysis. Subclasses may override this routine to |
| 1573 | /// provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1574 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1575 | ParmVarDecl *Param) { |
| 1576 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1577 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /// \brief Build a new C++ zero-initialization expression. |
| 1581 | /// |
| 1582 | /// By default, performs semantic analysis to build the new expression. |
| 1583 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 1584 | OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | SourceLocation LParenLoc, |
| 1586 | QualType T, |
| 1587 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1588 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1589 | T.getAsOpaquePtr(), LParenLoc, |
| 1590 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | 0, RParenLoc); |
| 1592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | /// \brief Build a new C++ "new" expression. |
| 1595 | /// |
| 1596 | /// By default, performs semantic analysis to build the new expression. |
| 1597 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1599 | bool UseGlobal, |
| 1600 | SourceLocation PlacementLParen, |
| 1601 | MultiExprArg PlacementArgs, |
| 1602 | SourceLocation PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1603 | SourceRange TypeIdParens, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | QualType AllocType, |
| 1605 | SourceLocation TypeLoc, |
| 1606 | SourceRange TypeRange, |
| 1607 | ExprArg ArraySize, |
| 1608 | SourceLocation ConstructorLParen, |
| 1609 | MultiExprArg ConstructorArgs, |
| 1610 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | PlacementLParen, |
| 1613 | move(PlacementArgs), |
| 1614 | PlacementRParen, |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1615 | TypeIdParens, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | AllocType, |
| 1617 | TypeLoc, |
| 1618 | TypeRange, |
| 1619 | move(ArraySize), |
| 1620 | ConstructorLParen, |
| 1621 | move(ConstructorArgs), |
| 1622 | ConstructorRParen); |
| 1623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | /// \brief Build a new C++ "delete" expression. |
| 1626 | /// |
| 1627 | /// By default, performs semantic analysis to build the new expression. |
| 1628 | /// Subclasses may override this routine to provide different behavior. |
| 1629 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1630 | bool IsGlobalDelete, |
| 1631 | bool IsArrayForm, |
| 1632 | ExprArg Operand) { |
| 1633 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1634 | move(Operand)); |
| 1635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1636 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | /// \brief Build a new unary type trait expression. |
| 1638 | /// |
| 1639 | /// By default, performs semantic analysis to build the new expression. |
| 1640 | /// Subclasses may override this routine to provide different behavior. |
| 1641 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1642 | SourceLocation StartLoc, |
| 1643 | SourceLocation LParenLoc, |
| 1644 | QualType T, |
| 1645 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | T.getAsOpaquePtr(), RParenLoc); |
| 1648 | } |
| 1649 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1651 | /// expression. |
| 1652 | /// |
| 1653 | /// By default, performs semantic analysis to build the new expression. |
| 1654 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1655 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | SourceRange QualifierRange, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1657 | const DeclarationNameInfo &NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1658 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1659 | CXXScopeSpec SS; |
| 1660 | SS.setRange(QualifierRange); |
| 1661 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1662 | |
| 1663 | if (TemplateArgs) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1664 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1665 | *TemplateArgs); |
| 1666 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1667 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /// \brief Build a new template-id expression. |
| 1671 | /// |
| 1672 | /// By default, performs semantic analysis to build the new expression. |
| 1673 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1674 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1675 | LookupResult &R, |
| 1676 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1677 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1678 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | /// \brief Build a new object-construction expression. |
| 1682 | /// |
| 1683 | /// By default, performs semantic analysis to build the new expression. |
| 1684 | /// Subclasses may override this routine to provide different behavior. |
| 1685 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1686 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1687 | CXXConstructorDecl *Constructor, |
| 1688 | bool IsElidable, |
| 1689 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1690 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1691 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1692 | ConvertedArgs)) |
| 1693 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1694 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1695 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1696 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | /// \brief Build a new object-construction expression. |
| 1700 | /// |
| 1701 | /// By default, performs semantic analysis to build the new expression. |
| 1702 | /// Subclasses may override this routine to provide different behavior. |
| 1703 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1704 | QualType T, |
| 1705 | SourceLocation LParenLoc, |
| 1706 | MultiExprArg Args, |
| 1707 | SourceLocation *Commas, |
| 1708 | SourceLocation RParenLoc) { |
| 1709 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1710 | T.getAsOpaquePtr(), |
| 1711 | LParenLoc, |
| 1712 | move(Args), |
| 1713 | Commas, |
| 1714 | RParenLoc); |
| 1715 | } |
| 1716 | |
| 1717 | /// \brief Build a new object-construction expression. |
| 1718 | /// |
| 1719 | /// By default, performs semantic analysis to build the new expression. |
| 1720 | /// Subclasses may override this routine to provide different behavior. |
| 1721 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1722 | QualType T, |
| 1723 | SourceLocation LParenLoc, |
| 1724 | MultiExprArg Args, |
| 1725 | SourceLocation *Commas, |
| 1726 | SourceLocation RParenLoc) { |
| 1727 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1728 | /*FIXME*/LParenLoc), |
| 1729 | T.getAsOpaquePtr(), |
| 1730 | LParenLoc, |
| 1731 | move(Args), |
| 1732 | Commas, |
| 1733 | RParenLoc); |
| 1734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1736 | /// \brief Build a new member reference expression. |
| 1737 | /// |
| 1738 | /// By default, performs semantic analysis to build the new expression. |
| 1739 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1740 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1741 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1742 | bool IsArrow, |
| 1743 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1744 | NestedNameSpecifier *Qualifier, |
| 1745 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1746 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1747 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1748 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1749 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1750 | SS.setRange(QualifierRange); |
| 1751 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1753 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1754 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1755 | SS, FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1756 | MemberNameInfo, |
| 1757 | TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1760 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1761 | /// |
| 1762 | /// By default, performs semantic analysis to build the new expression. |
| 1763 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1764 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1765 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1766 | SourceLocation OperatorLoc, |
| 1767 | bool IsArrow, |
| 1768 | NestedNameSpecifier *Qualifier, |
| 1769 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1770 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1771 | LookupResult &R, |
| 1772 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1773 | CXXScopeSpec SS; |
| 1774 | SS.setRange(QualifierRange); |
| 1775 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1777 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1778 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1779 | SS, FirstQualifierInScope, |
| 1780 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1781 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1783 | /// \brief Build a new Objective-C @encode expression. |
| 1784 | /// |
| 1785 | /// By default, performs semantic analysis to build the new expression. |
| 1786 | /// Subclasses may override this routine to provide different behavior. |
| 1787 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1788 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | SourceLocation RParenLoc) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1790 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1793 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1794 | /// \brief Build a new Objective-C class message. |
| 1795 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1796 | Selector Sel, |
| 1797 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1798 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1799 | MultiExprArg Args, |
| 1800 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1801 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1802 | ReceiverTypeInfo->getType(), |
| 1803 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1804 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1805 | move(Args)); |
| 1806 | } |
| 1807 | |
| 1808 | /// \brief Build a new Objective-C instance message. |
| 1809 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1810 | Selector Sel, |
| 1811 | ObjCMethodDecl *Method, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1812 | SourceLocation LBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1813 | MultiExprArg Args, |
| 1814 | SourceLocation RBracLoc) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1815 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1816 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1817 | ReceiverType, |
| 1818 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | f49bb08 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1819 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1820 | move(Args)); |
| 1821 | } |
| 1822 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1823 | /// \brief Build a new Objective-C ivar reference expression. |
| 1824 | /// |
| 1825 | /// By default, performs semantic analysis to build the new expression. |
| 1826 | /// Subclasses may override this routine to provide different behavior. |
| 1827 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1828 | SourceLocation IvarLoc, |
| 1829 | bool IsArrow, bool IsFreeIvar) { |
| 1830 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1831 | CXXScopeSpec SS; |
| 1832 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1833 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1834 | Sema::LookupMemberName); |
| 1835 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1836 | /*FIME:*/IvarLoc, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1837 | SS, DeclPtrTy(), |
| 1838 | false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1839 | if (Result.isInvalid()) |
| 1840 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1841 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1842 | if (Result.get()) |
| 1843 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1844 | |
| 1845 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1846 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1847 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1848 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1849 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1850 | /*TemplateArgs=*/0); |
| 1851 | } |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1852 | |
| 1853 | /// \brief Build a new Objective-C property reference expression. |
| 1854 | /// |
| 1855 | /// By default, performs semantic analysis to build the new expression. |
| 1856 | /// Subclasses may override this routine to provide different behavior. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1857 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1858 | ObjCPropertyDecl *Property, |
| 1859 | SourceLocation PropertyLoc) { |
| 1860 | CXXScopeSpec SS; |
| 1861 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1862 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1863 | Sema::LookupMemberName); |
| 1864 | bool IsArrow = false; |
| 1865 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1866 | /*FIME:*/PropertyLoc, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1867 | SS, DeclPtrTy(), |
| 1868 | false); |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1869 | if (Result.isInvalid()) |
| 1870 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1872 | if (Result.get()) |
| 1873 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1874 | |
| 1875 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1876 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1877 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1878 | SS, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1879 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1880 | R, |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1881 | /*TemplateArgs=*/0); |
| 1882 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1883 | |
| 1884 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1885 | /// expression. |
| 1886 | /// |
| 1887 | /// By default, performs semantic analysis to build the new expression. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1888 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1889 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1890 | ObjCMethodDecl *Getter, |
| 1891 | QualType T, |
| 1892 | ObjCMethodDecl *Setter, |
| 1893 | SourceLocation NameLoc, |
| 1894 | ExprArg Base) { |
| 1895 | // Since these expressions can only be value-dependent, we do not need to |
| 1896 | // perform semantic analysis again. |
| 1897 | return getSema().Owned( |
| 1898 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1899 | Setter, |
| 1900 | NameLoc, |
| 1901 | Base.takeAs<Expr>())); |
| 1902 | } |
| 1903 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1904 | /// \brief Build a new Objective-C "isa" expression. |
| 1905 | /// |
| 1906 | /// By default, performs semantic analysis to build the new expression. |
| 1907 | /// Subclasses may override this routine to provide different behavior. |
| 1908 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1909 | bool IsArrow) { |
| 1910 | CXXScopeSpec SS; |
| 1911 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1912 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1913 | Sema::LookupMemberName); |
| 1914 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1915 | /*FIME:*/IsaLoc, |
John McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1916 | SS, DeclPtrTy(), |
| 1917 | false); |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1918 | if (Result.isInvalid()) |
| 1919 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1920 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1921 | if (Result.get()) |
| 1922 | return move(Result); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1923 | |
| 1924 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1925 | Base->getType(), |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1926 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1927 | /*FirstQualifierInScope=*/0, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1928 | R, |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1929 | /*TemplateArgs=*/0); |
| 1930 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1931 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1932 | /// \brief Build a new shuffle vector expression. |
| 1933 | /// |
| 1934 | /// By default, performs semantic analysis to build the new expression. |
| 1935 | /// Subclasses may override this routine to provide different behavior. |
| 1936 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1937 | MultiExprArg SubExprs, |
| 1938 | SourceLocation RParenLoc) { |
| 1939 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1941 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1942 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1943 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1944 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1945 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1946 | // Build a reference to the __builtin_shufflevector builtin |
| 1947 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1948 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1949 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1950 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1951 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1952 | |
| 1953 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1954 | unsigned NumSubExprs = SubExprs.size(); |
| 1955 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1956 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1957 | Subs, NumSubExprs, |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 1958 | Builtin->getCallResultType(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1959 | RParenLoc); |
| 1960 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | // Type-check the __builtin_shufflevector expression. |
| 1963 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1964 | if (Result.isInvalid()) |
| 1965 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1967 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1968 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1969 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1970 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1971 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1972 | template<typename Derived> |
| 1973 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1974 | if (!S) |
| 1975 | return SemaRef.Owned(S); |
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 | switch (S->getStmtClass()) { |
| 1978 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1980 | // Transform individual statement nodes |
| 1981 | #define STMT(Node, Parent) \ |
| 1982 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1983 | #define EXPR(Node, Parent) |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1984 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1986 | // Transform expressions by calling TransformExpr. |
| 1987 | #define STMT(Node, Parent) |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 1988 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1989 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1990 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1991 | { |
| 1992 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1993 | if (E.isInvalid()) |
| 1994 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1996 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1997 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2000 | return SemaRef.Owned(S->Retain()); |
| 2001 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2002 | |
| 2003 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2004 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2005 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2006 | if (!E) |
| 2007 | return SemaRef.Owned(E); |
| 2008 | |
| 2009 | switch (E->getStmtClass()) { |
| 2010 | case Stmt::NoStmtClass: break; |
| 2011 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2012 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2013 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2014 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2015 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2018 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2022 | NestedNameSpecifier * |
| 2023 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2024 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2025 | QualType ObjectType, |
| 2026 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2027 | if (!NNS) |
| 2028 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2030 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2031 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2032 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2033 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2034 | ObjectType, |
| 2035 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2036 | if (!Prefix) |
| 2037 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2038 | |
| 2039 | // 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] | 2040 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2041 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2042 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2043 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2045 | switch (NNS->getKind()) { |
| 2046 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2047 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2048 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2049 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2050 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2051 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2052 | |
| 2053 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2054 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2055 | ObjectType, |
| 2056 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2057 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2058 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2059 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2060 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2061 | getDerived().TransformDecl(Range.getBegin(), |
| 2062 | NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2063 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2064 | Prefix == NNS->getPrefix() && |
| 2065 | NS == NNS->getAsNamespace()) |
| 2066 | return NNS; |
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 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2071 | case NestedNameSpecifier::Global: |
| 2072 | // There is no meaningful transformation that one could perform on the |
| 2073 | // global scope. |
| 2074 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2075 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2076 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2077 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2078 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2079 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2080 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2081 | if (T.isNull()) |
| 2082 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2083 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2084 | if (!getDerived().AlwaysRebuild() && |
| 2085 | Prefix == NNS->getPrefix() && |
| 2086 | T == QualType(NNS->getAsType(), 0)) |
| 2087 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2088 | |
| 2089 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2090 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2091 | T); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2092 | } |
| 2093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2095 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2096 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | template<typename Derived> |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2100 | DeclarationNameInfo |
| 2101 | TreeTransform<Derived> |
| 2102 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 2103 | QualType ObjectType) { |
| 2104 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2105 | if (!Name) |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2106 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2107 | |
| 2108 | switch (Name.getNameKind()) { |
| 2109 | case DeclarationName::Identifier: |
| 2110 | case DeclarationName::ObjCZeroArgSelector: |
| 2111 | case DeclarationName::ObjCOneArgSelector: |
| 2112 | case DeclarationName::ObjCMultiArgSelector: |
| 2113 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2114 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2115 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2116 | return NameInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2117 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2118 | case DeclarationName::CXXConstructorName: |
| 2119 | case DeclarationName::CXXDestructorName: |
| 2120 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2121 | TypeSourceInfo *NewTInfo; |
| 2122 | CanQualType NewCanTy; |
| 2123 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| 2124 | NewTInfo = getDerived().TransformType(OldTInfo, ObjectType); |
| 2125 | if (!NewTInfo) |
| 2126 | return DeclarationNameInfo(); |
| 2127 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| 2128 | } |
| 2129 | else { |
| 2130 | NewTInfo = 0; |
| 2131 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| 2132 | QualType NewT = getDerived().TransformType(Name.getCXXNameType(), |
| 2133 | ObjectType); |
| 2134 | if (NewT.isNull()) |
| 2135 | return DeclarationNameInfo(); |
| 2136 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2138 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2139 | DeclarationName NewName |
| 2140 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2141 | NewCanTy); |
| 2142 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2143 | NewNameInfo.setName(NewName); |
| 2144 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2145 | return NewNameInfo; |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2149 | assert(0 && "Unknown name kind."); |
| 2150 | return DeclarationNameInfo(); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2154 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2155 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2156 | QualType ObjectType) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2157 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2158 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2159 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2161 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2162 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2163 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2164 | if (!NNS) |
| 2165 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2167 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2169 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2170 | if (!TransTemplate) |
| 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() && |
| 2174 | NNS == QTN->getQualifier() && |
| 2175 | TransTemplate == Template) |
| 2176 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2177 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2178 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2179 | TransTemplate); |
| 2180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2182 | // These should be getting filtered out before they make it into the AST. |
| 2183 | assert(false && "overloaded template name survived to here"); |
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 (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2187 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2188 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2189 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2190 | ObjectType); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2191 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2192 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2194 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2195 | NNS == DTN->getQualifier() && |
| 2196 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2197 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2199 | if (DTN->isIdentifier()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2200 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2201 | ObjectType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2202 | |
| 2203 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2204 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2206 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2207 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 | TemplateDecl *TransTemplate |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2209 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2210 | if (!TransTemplate) |
| 2211 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2213 | if (!getDerived().AlwaysRebuild() && |
| 2214 | TransTemplate == Template) |
| 2215 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2216 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2217 | return TemplateName(TransTemplate); |
| 2218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2219 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2220 | // These should be getting filtered out before they reach the AST. |
| 2221 | assert(false && "overloaded function decl survived to here"); |
| 2222 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2226 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2227 | const TemplateArgument &Arg, |
| 2228 | TemplateArgumentLoc &Output) { |
| 2229 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2230 | switch (Arg.getKind()) { |
| 2231 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2232 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2233 | break; |
| 2234 | |
| 2235 | case TemplateArgument::Type: |
| 2236 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2237 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2238 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2241 | case TemplateArgument::Template: |
| 2242 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2243 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2244 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2245 | case TemplateArgument::Expression: |
| 2246 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2247 | break; |
| 2248 | |
| 2249 | case TemplateArgument::Declaration: |
| 2250 | case TemplateArgument::Integral: |
| 2251 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2252 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2253 | break; |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | template<typename Derived> |
| 2258 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2259 | const TemplateArgumentLoc &Input, |
| 2260 | TemplateArgumentLoc &Output) { |
| 2261 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2262 | switch (Arg.getKind()) { |
| 2263 | case TemplateArgument::Null: |
| 2264 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2265 | Output = Input; |
| 2266 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2267 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2268 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2269 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2270 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2271 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2272 | |
| 2273 | DI = getDerived().TransformType(DI); |
| 2274 | if (!DI) return true; |
| 2275 | |
| 2276 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2277 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2279 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2280 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2281 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2282 | DeclarationName Name; |
| 2283 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2284 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2285 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2286 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2287 | if (!D) return true; |
| 2288 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2289 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2290 | if (SourceExpr) { |
| 2291 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2292 | Action::Unevaluated); |
| 2293 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2294 | if (E.isInvalid()) |
| 2295 | SourceExpr = NULL; |
| 2296 | else { |
| 2297 | SourceExpr = E.takeAs<Expr>(); |
| 2298 | SourceExpr->Retain(); |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2303 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2305 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2306 | case TemplateArgument::Template: { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2307 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2308 | TemplateName Template |
| 2309 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2310 | if (Template.isNull()) |
| 2311 | return true; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2312 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2313 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2314 | Input.getTemplateQualifierRange(), |
| 2315 | Input.getTemplateNameLoc()); |
| 2316 | return false; |
| 2317 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2318 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2319 | case TemplateArgument::Expression: { |
| 2320 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2321 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2322 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2324 | Expr *InputExpr = Input.getSourceExpression(); |
| 2325 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2326 | |
| 2327 | Sema::OwningExprResult E |
| 2328 | = getDerived().TransformExpr(InputExpr); |
| 2329 | if (E.isInvalid()) return true; |
| 2330 | |
| 2331 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2332 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2333 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2334 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2335 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2337 | case TemplateArgument::Pack: { |
| 2338 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2339 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2340 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2341 | AEnd = Arg.pack_end(); |
| 2342 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2343 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2344 | // FIXME: preserve source information here when we start |
| 2345 | // caring about parameter packs. |
| 2346 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2347 | TemplateArgumentLoc InputArg; |
| 2348 | TemplateArgumentLoc OutputArg; |
| 2349 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2350 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2351 | return true; |
| 2352 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2353 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2354 | } |
| 2355 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2356 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2357 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2358 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2359 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2360 | } |
| 2361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2362 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2363 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2364 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2367 | //===----------------------------------------------------------------------===// |
| 2368 | // Type transformation |
| 2369 | //===----------------------------------------------------------------------===// |
| 2370 | |
| 2371 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2372 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2373 | QualType ObjectType) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2374 | if (getDerived().AlreadyTransformed(T)) |
| 2375 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2376 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2377 | // Temporary workaround. All of these transformations should |
| 2378 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2379 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2380 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2381 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2382 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2383 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2384 | if (!NewDI) |
| 2385 | return QualType(); |
| 2386 | |
| 2387 | return NewDI->getType(); |
| 2388 | } |
| 2389 | |
| 2390 | template<typename Derived> |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2391 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2392 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2393 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2394 | return DI; |
| 2395 | |
| 2396 | TypeLocBuilder TLB; |
| 2397 | |
| 2398 | TypeLoc TL = DI->getTypeLoc(); |
| 2399 | TLB.reserve(TL.getFullDataSize()); |
| 2400 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2401 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2402 | if (Result.isNull()) |
| 2403 | return 0; |
| 2404 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2405 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | template<typename Derived> |
| 2409 | QualType |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2410 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2411 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2412 | switch (T.getTypeLocClass()) { |
| 2413 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2414 | #define TYPELOC(CLASS, PARENT) \ |
| 2415 | case TypeLoc::CLASS: \ |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2416 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2417 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2419 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2420 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2421 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2422 | return QualType(); |
| 2423 | } |
| 2424 | |
| 2425 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2426 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2427 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2428 | /// types). This is the right thing for template instantiation, but |
| 2429 | /// probably not for other clients. |
| 2430 | template<typename Derived> |
| 2431 | QualType |
| 2432 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2433 | QualifiedTypeLoc T, |
| 2434 | QualType ObjectType) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2435 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2436 | |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2437 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2438 | ObjectType); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2439 | if (Result.isNull()) |
| 2440 | return QualType(); |
| 2441 | |
| 2442 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2443 | // FIXME: this is the right thing for template instantiation, but |
| 2444 | // probably not for other clients. |
| 2445 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2446 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2447 | |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 2448 | if (!Quals.empty()) { |
| 2449 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 2450 | TLB.push<QualifiedTypeLoc>(Result); |
| 2451 | // No location information to preserve. |
| 2452 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2453 | |
| 2454 | return Result; |
| 2455 | } |
| 2456 | |
| 2457 | template <class TyLoc> static inline |
| 2458 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2459 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2460 | NewT.setNameLoc(T.getNameLoc()); |
| 2461 | return T.getType(); |
| 2462 | } |
| 2463 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2464 | template<typename Derived> |
| 2465 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2466 | BuiltinTypeLoc T, |
| 2467 | QualType ObjectType) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2468 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2469 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2470 | if (T.needsExtraLocalData()) |
| 2471 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2472 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2473 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2474 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2475 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2476 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2477 | ComplexTypeLoc T, |
| 2478 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2479 | // FIXME: recurse? |
| 2480 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2481 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2482 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2483 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2484 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2485 | PointerTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2486 | QualType ObjectType) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2487 | QualType PointeeType |
| 2488 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2489 | if (PointeeType.isNull()) |
| 2490 | return QualType(); |
| 2491 | |
| 2492 | QualType Result = TL.getType(); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2493 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2494 | // A dependent pointer type 'T *' has is being transformed such |
| 2495 | // that an Objective-C class type is being replaced for 'T'. The |
| 2496 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2497 | // PointerType. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2498 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2499 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2500 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2501 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2502 | return Result; |
| 2503 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2504 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2505 | if (getDerived().AlwaysRebuild() || |
| 2506 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2507 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2508 | if (Result.isNull()) |
| 2509 | return QualType(); |
| 2510 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2511 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2512 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2513 | NewT.setSigilLoc(TL.getSigilLoc()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2514 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2516 | |
| 2517 | template<typename Derived> |
| 2518 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2519 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2520 | BlockPointerTypeLoc TL, |
| 2521 | QualType ObjectType) { |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2522 | QualType PointeeType |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2523 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2524 | if (PointeeType.isNull()) |
| 2525 | return QualType(); |
| 2526 | |
| 2527 | QualType Result = TL.getType(); |
| 2528 | if (getDerived().AlwaysRebuild() || |
| 2529 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2530 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2531 | TL.getSigilLoc()); |
| 2532 | if (Result.isNull()) |
| 2533 | return QualType(); |
| 2534 | } |
| 2535 | |
Douglas Gregor | 39968ad | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2536 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | db93c4a | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2537 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2538 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2541 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2542 | /// don't care whether the type itself is an l-value type or an r-value |
| 2543 | /// type; we only care if the type was *written* as an l-value type |
| 2544 | /// or an r-value type. |
| 2545 | template<typename Derived> |
| 2546 | QualType |
| 2547 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2548 | ReferenceTypeLoc TL, |
| 2549 | QualType ObjectType) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2550 | const ReferenceType *T = TL.getTypePtr(); |
| 2551 | |
| 2552 | // Note that this works with the pointee-as-written. |
| 2553 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2554 | if (PointeeType.isNull()) |
| 2555 | return QualType(); |
| 2556 | |
| 2557 | QualType Result = TL.getType(); |
| 2558 | if (getDerived().AlwaysRebuild() || |
| 2559 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2560 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2561 | T->isSpelledAsLValue(), |
| 2562 | TL.getSigilLoc()); |
| 2563 | if (Result.isNull()) |
| 2564 | return QualType(); |
| 2565 | } |
| 2566 | |
| 2567 | // r-value references can be rebuilt as l-value references. |
| 2568 | ReferenceTypeLoc NewTL; |
| 2569 | if (isa<LValueReferenceType>(Result)) |
| 2570 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2571 | else |
| 2572 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2573 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2574 | |
| 2575 | return Result; |
| 2576 | } |
| 2577 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | template<typename Derived> |
| 2579 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2580 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2581 | LValueReferenceTypeLoc TL, |
| 2582 | QualType ObjectType) { |
| 2583 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2586 | template<typename Derived> |
| 2587 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2588 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2589 | RValueReferenceTypeLoc TL, |
| 2590 | QualType ObjectType) { |
| 2591 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2593 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2594 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2595 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2596 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2597 | MemberPointerTypeLoc TL, |
| 2598 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2599 | MemberPointerType *T = TL.getTypePtr(); |
| 2600 | |
| 2601 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2602 | if (PointeeType.isNull()) |
| 2603 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2605 | // TODO: preserve source information for this. |
| 2606 | QualType ClassType |
| 2607 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2608 | if (ClassType.isNull()) |
| 2609 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2611 | QualType Result = TL.getType(); |
| 2612 | if (getDerived().AlwaysRebuild() || |
| 2613 | PointeeType != T->getPointeeType() || |
| 2614 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2615 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2616 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2617 | if (Result.isNull()) |
| 2618 | return QualType(); |
| 2619 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2620 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2621 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2622 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2623 | |
| 2624 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2627 | template<typename Derived> |
| 2628 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2629 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2630 | ConstantArrayTypeLoc TL, |
| 2631 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2632 | ConstantArrayType *T = TL.getTypePtr(); |
| 2633 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2634 | if (ElementType.isNull()) |
| 2635 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2636 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2637 | QualType Result = TL.getType(); |
| 2638 | if (getDerived().AlwaysRebuild() || |
| 2639 | ElementType != T->getElementType()) { |
| 2640 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2641 | T->getSizeModifier(), |
| 2642 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2643 | T->getIndexTypeCVRQualifiers(), |
| 2644 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2645 | if (Result.isNull()) |
| 2646 | return QualType(); |
| 2647 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2648 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2650 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2651 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2652 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2653 | Expr *Size = TL.getSizeExpr(); |
| 2654 | if (Size) { |
| 2655 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2656 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2657 | } |
| 2658 | NewTL.setSizeExpr(Size); |
| 2659 | |
| 2660 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2661 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2662 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2663 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2664 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2665 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2666 | IncompleteArrayTypeLoc TL, |
| 2667 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2669 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2670 | if (ElementType.isNull()) |
| 2671 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2672 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2673 | QualType Result = TL.getType(); |
| 2674 | if (getDerived().AlwaysRebuild() || |
| 2675 | ElementType != T->getElementType()) { |
| 2676 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2677 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2678 | T->getIndexTypeCVRQualifiers(), |
| 2679 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2680 | if (Result.isNull()) |
| 2681 | return QualType(); |
| 2682 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2683 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2684 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2685 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2686 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2687 | NewTL.setSizeExpr(0); |
| 2688 | |
| 2689 | return Result; |
| 2690 | } |
| 2691 | |
| 2692 | template<typename Derived> |
| 2693 | QualType |
| 2694 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2695 | VariableArrayTypeLoc TL, |
| 2696 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2697 | VariableArrayType *T = TL.getTypePtr(); |
| 2698 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2699 | if (ElementType.isNull()) |
| 2700 | return QualType(); |
| 2701 | |
| 2702 | // Array bounds are not potentially evaluated contexts |
| 2703 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2704 | |
| 2705 | Sema::OwningExprResult SizeResult |
| 2706 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2707 | if (SizeResult.isInvalid()) |
| 2708 | return QualType(); |
| 2709 | |
| 2710 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2711 | |
| 2712 | QualType Result = TL.getType(); |
| 2713 | if (getDerived().AlwaysRebuild() || |
| 2714 | ElementType != T->getElementType() || |
| 2715 | Size != T->getSizeExpr()) { |
| 2716 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2717 | T->getSizeModifier(), |
| 2718 | move(SizeResult), |
| 2719 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2720 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2721 | if (Result.isNull()) |
| 2722 | return QualType(); |
| 2723 | } |
| 2724 | else SizeResult.take(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2725 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2727 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2728 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2729 | NewTL.setSizeExpr(Size); |
| 2730 | |
| 2731 | return Result; |
| 2732 | } |
| 2733 | |
| 2734 | template<typename Derived> |
| 2735 | QualType |
| 2736 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2737 | DependentSizedArrayTypeLoc TL, |
| 2738 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2739 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2740 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2741 | if (ElementType.isNull()) |
| 2742 | return QualType(); |
| 2743 | |
| 2744 | // Array bounds are not potentially evaluated contexts |
| 2745 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2746 | |
| 2747 | Sema::OwningExprResult SizeResult |
| 2748 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2749 | if (SizeResult.isInvalid()) |
| 2750 | return QualType(); |
| 2751 | |
| 2752 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2753 | |
| 2754 | QualType Result = TL.getType(); |
| 2755 | if (getDerived().AlwaysRebuild() || |
| 2756 | ElementType != T->getElementType() || |
| 2757 | Size != T->getSizeExpr()) { |
| 2758 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2759 | T->getSizeModifier(), |
| 2760 | move(SizeResult), |
| 2761 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2762 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2763 | if (Result.isNull()) |
| 2764 | return QualType(); |
| 2765 | } |
| 2766 | else SizeResult.take(); |
| 2767 | |
| 2768 | // We might have any sort of array type now, but fortunately they |
| 2769 | // all have the same location layout. |
| 2770 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2771 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2772 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2773 | NewTL.setSizeExpr(Size); |
| 2774 | |
| 2775 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2777 | |
| 2778 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2779 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2781 | DependentSizedExtVectorTypeLoc TL, |
| 2782 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2784 | |
| 2785 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2786 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2787 | if (ElementType.isNull()) |
| 2788 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2789 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2790 | // Vector sizes are not potentially evaluated contexts |
| 2791 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2792 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2793 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2794 | if (Size.isInvalid()) |
| 2795 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2796 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | QualType Result = TL.getType(); |
| 2798 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2799 | ElementType != T->getElementType() || |
| 2800 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2801 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2802 | move(Size), |
| 2803 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2804 | if (Result.isNull()) |
| 2805 | return QualType(); |
| 2806 | } |
| 2807 | else Size.take(); |
| 2808 | |
| 2809 | // Result might be dependent or not. |
| 2810 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2811 | DependentSizedExtVectorTypeLoc NewTL |
| 2812 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2813 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2814 | } else { |
| 2815 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2816 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2817 | } |
| 2818 | |
| 2819 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2821 | |
| 2822 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2823 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2824 | VectorTypeLoc TL, |
| 2825 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2826 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2827 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2828 | if (ElementType.isNull()) |
| 2829 | return QualType(); |
| 2830 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2831 | QualType Result = TL.getType(); |
| 2832 | if (getDerived().AlwaysRebuild() || |
| 2833 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2834 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2835 | T->getAltiVecSpecific()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2836 | if (Result.isNull()) |
| 2837 | return QualType(); |
| 2838 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2839 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2840 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2841 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2842 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2843 | return Result; |
| 2844 | } |
| 2845 | |
| 2846 | template<typename Derived> |
| 2847 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2848 | ExtVectorTypeLoc TL, |
| 2849 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2850 | VectorType *T = TL.getTypePtr(); |
| 2851 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2852 | if (ElementType.isNull()) |
| 2853 | return QualType(); |
| 2854 | |
| 2855 | QualType Result = TL.getType(); |
| 2856 | if (getDerived().AlwaysRebuild() || |
| 2857 | ElementType != T->getElementType()) { |
| 2858 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2859 | T->getNumElements(), |
| 2860 | /*FIXME*/ SourceLocation()); |
| 2861 | if (Result.isNull()) |
| 2862 | return QualType(); |
| 2863 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2864 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2865 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2866 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2867 | |
| 2868 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2869 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2870 | |
| 2871 | template<typename Derived> |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2872 | ParmVarDecl * |
| 2873 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2874 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2875 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2876 | if (!NewDI) |
| 2877 | return 0; |
| 2878 | |
| 2879 | if (NewDI == OldDI) |
| 2880 | return OldParm; |
| 2881 | else |
| 2882 | return ParmVarDecl::Create(SemaRef.Context, |
| 2883 | OldParm->getDeclContext(), |
| 2884 | OldParm->getLocation(), |
| 2885 | OldParm->getIdentifier(), |
| 2886 | NewDI->getType(), |
| 2887 | NewDI, |
| 2888 | OldParm->getStorageClass(), |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2889 | OldParm->getStorageClassAsWritten(), |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2890 | /* DefArg */ NULL); |
| 2891 | } |
| 2892 | |
| 2893 | template<typename Derived> |
| 2894 | bool TreeTransform<Derived>:: |
| 2895 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2896 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2897 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2898 | FunctionProtoType *T = TL.getTypePtr(); |
| 2899 | |
| 2900 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2901 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2902 | |
| 2903 | QualType NewType; |
| 2904 | ParmVarDecl *NewParm; |
| 2905 | |
| 2906 | if (OldParm) { |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2907 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2908 | if (!NewParm) |
| 2909 | return true; |
| 2910 | NewType = NewParm->getType(); |
| 2911 | |
| 2912 | // Deal with the possibility that we don't have a parameter |
| 2913 | // declaration for this parameter. |
| 2914 | } else { |
| 2915 | NewParm = 0; |
| 2916 | |
| 2917 | QualType OldType = T->getArgType(i); |
| 2918 | NewType = getDerived().TransformType(OldType); |
| 2919 | if (NewType.isNull()) |
| 2920 | return true; |
| 2921 | } |
| 2922 | |
| 2923 | PTypes.push_back(NewType); |
| 2924 | PVars.push_back(NewParm); |
| 2925 | } |
| 2926 | |
| 2927 | return false; |
| 2928 | } |
| 2929 | |
| 2930 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2933 | FunctionProtoTypeLoc TL, |
| 2934 | QualType ObjectType) { |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2935 | // Transform the parameters. We do this first for the benefit of template |
| 2936 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2937 | // instantiation scope before we transform the function type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2938 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2939 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 21ef0fa | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2940 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2941 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2942 | |
Douglas Gregor | 895162d | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2943 | FunctionProtoType *T = TL.getTypePtr(); |
| 2944 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2945 | if (ResultType.isNull()) |
| 2946 | return QualType(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2947 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2948 | QualType Result = TL.getType(); |
| 2949 | if (getDerived().AlwaysRebuild() || |
| 2950 | ResultType != T->getResultType() || |
| 2951 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2952 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2953 | ParamTypes.data(), |
| 2954 | ParamTypes.size(), |
| 2955 | T->isVariadic(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 2956 | T->getTypeQuals(), |
| 2957 | T->getExtInfo()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2958 | if (Result.isNull()) |
| 2959 | return QualType(); |
| 2960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2962 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2963 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2964 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2965 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2966 | NewTL.setArg(i, ParamDecls[i]); |
| 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 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2971 | template<typename Derived> |
| 2972 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2973 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2974 | FunctionNoProtoTypeLoc TL, |
| 2975 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2976 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2977 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2978 | if (ResultType.isNull()) |
| 2979 | return QualType(); |
| 2980 | |
| 2981 | QualType Result = TL.getType(); |
| 2982 | if (getDerived().AlwaysRebuild() || |
| 2983 | ResultType != T->getResultType()) |
| 2984 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2985 | |
| 2986 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2987 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2988 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2989 | |
| 2990 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2993 | template<typename Derived> QualType |
| 2994 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2995 | UnresolvedUsingTypeLoc TL, |
| 2996 | QualType ObjectType) { |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2997 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2998 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2999 | if (!D) |
| 3000 | return QualType(); |
| 3001 | |
| 3002 | QualType Result = TL.getType(); |
| 3003 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 3004 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 3005 | if (Result.isNull()) |
| 3006 | return QualType(); |
| 3007 | } |
| 3008 | |
| 3009 | // We might get an arbitrary type spec type back. We should at |
| 3010 | // least always get a type spec type, though. |
| 3011 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 3012 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3013 | |
| 3014 | return Result; |
| 3015 | } |
| 3016 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3017 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3018 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3019 | TypedefTypeLoc TL, |
| 3020 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3021 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3022 | TypedefDecl *Typedef |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3023 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3024 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3025 | if (!Typedef) |
| 3026 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3028 | QualType Result = TL.getType(); |
| 3029 | if (getDerived().AlwaysRebuild() || |
| 3030 | Typedef != T->getDecl()) { |
| 3031 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3032 | if (Result.isNull()) |
| 3033 | return QualType(); |
| 3034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3036 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3037 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3038 | |
| 3039 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3041 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3042 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3043 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3044 | TypeOfExprTypeLoc TL, |
| 3045 | QualType ObjectType) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3046 | // typeof expressions are not potentially evaluated contexts |
| 3047 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3049 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3050 | if (E.isInvalid()) |
| 3051 | return QualType(); |
| 3052 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3053 | QualType Result = TL.getType(); |
| 3054 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3055 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3056 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3057 | if (Result.isNull()) |
| 3058 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3059 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3060 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3063 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3064 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3065 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3066 | |
| 3067 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3069 | |
| 3070 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3071 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3072 | TypeOfTypeLoc TL, |
| 3073 | QualType ObjectType) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3074 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3075 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3076 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3077 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3079 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3080 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3081 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3082 | if (Result.isNull()) |
| 3083 | return QualType(); |
| 3084 | } |
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 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3087 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3088 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3089 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3090 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3091 | |
| 3092 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
| 3095 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3096 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3097 | DecltypeTypeLoc TL, |
| 3098 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3099 | DecltypeType *T = TL.getTypePtr(); |
| 3100 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3101 | // decltype expressions are not potentially evaluated contexts |
| 3102 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3104 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3105 | if (E.isInvalid()) |
| 3106 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3107 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3108 | QualType Result = TL.getType(); |
| 3109 | if (getDerived().AlwaysRebuild() || |
| 3110 | E.get() != T->getUnderlyingExpr()) { |
| 3111 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3112 | if (Result.isNull()) |
| 3113 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3114 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3115 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3116 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3117 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3118 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3119 | |
| 3120 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3124 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3125 | RecordTypeLoc TL, |
| 3126 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3127 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3128 | RecordDecl *Record |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3129 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3130 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3131 | if (!Record) |
| 3132 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3134 | QualType Result = TL.getType(); |
| 3135 | if (getDerived().AlwaysRebuild() || |
| 3136 | Record != T->getDecl()) { |
| 3137 | Result = getDerived().RebuildRecordType(Record); |
| 3138 | if (Result.isNull()) |
| 3139 | return QualType(); |
| 3140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3141 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3142 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3143 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3144 | |
| 3145 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3147 | |
| 3148 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3149 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3150 | EnumTypeLoc TL, |
| 3151 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3152 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3153 | EnumDecl *Enum |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3154 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3155 | T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3156 | if (!Enum) |
| 3157 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3159 | QualType Result = TL.getType(); |
| 3160 | if (getDerived().AlwaysRebuild() || |
| 3161 | Enum != T->getDecl()) { |
| 3162 | Result = getDerived().RebuildEnumType(Enum); |
| 3163 | if (Result.isNull()) |
| 3164 | return QualType(); |
| 3165 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3167 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3168 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3169 | |
| 3170 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3171 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3172 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3173 | template<typename Derived> |
| 3174 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3175 | TypeLocBuilder &TLB, |
| 3176 | InjectedClassNameTypeLoc TL, |
| 3177 | QualType ObjectType) { |
| 3178 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3179 | TL.getTypePtr()->getDecl()); |
| 3180 | if (!D) return QualType(); |
| 3181 | |
| 3182 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3183 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3184 | return T; |
| 3185 | } |
| 3186 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3187 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3188 | template<typename Derived> |
| 3189 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3190 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3191 | TemplateTypeParmTypeLoc TL, |
| 3192 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3193 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3197 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3198 | TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3199 | SubstTemplateTypeParmTypeLoc TL, |
| 3200 | QualType ObjectType) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3201 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3205 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3206 | const TemplateSpecializationType *TST, |
| 3207 | QualType ObjectType) { |
| 3208 | // FIXME: this entire method is a temporary workaround; callers |
| 3209 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3210 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3211 | // Fake up a TemplateSpecializationTypeLoc. |
| 3212 | TypeLocBuilder TLB; |
| 3213 | TemplateSpecializationTypeLoc TL |
| 3214 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3215 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3216 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3217 | |
| 3218 | TL.setTemplateNameLoc(BaseLoc); |
| 3219 | TL.setLAngleLoc(BaseLoc); |
| 3220 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3221 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3222 | const TemplateArgument &TA = TST->getArg(i); |
| 3223 | TemplateArgumentLoc TAL; |
| 3224 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3225 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3226 | } |
| 3227 | |
| 3228 | TypeLocBuilder IgnoredTLB; |
| 3229 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3230 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3231 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3232 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3233 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3234 | TypeLocBuilder &TLB, |
| 3235 | TemplateSpecializationTypeLoc TL, |
| 3236 | QualType ObjectType) { |
| 3237 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3238 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3239 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3240 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3241 | if (Template.isNull()) |
| 3242 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3243 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3244 | TemplateArgumentListInfo NewTemplateArgs; |
| 3245 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3246 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3247 | |
| 3248 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3249 | TemplateArgumentLoc Loc; |
| 3250 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3251 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3252 | NewTemplateArgs.addArgument(Loc); |
| 3253 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3255 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3256 | |
| 3257 | QualType Result = |
| 3258 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3259 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3260 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3261 | |
| 3262 | if (!Result.isNull()) { |
| 3263 | TemplateSpecializationTypeLoc NewTL |
| 3264 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3265 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3266 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3267 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3268 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3269 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3270 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3271 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3272 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3273 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3274 | |
| 3275 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3276 | QualType |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3277 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 3278 | ElaboratedTypeLoc TL, |
| 3279 | QualType ObjectType) { |
| 3280 | ElaboratedType *T = TL.getTypePtr(); |
| 3281 | |
| 3282 | NestedNameSpecifier *NNS = 0; |
| 3283 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 3284 | if (T->getQualifier() != 0) { |
| 3285 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3286 | TL.getQualifierRange(), |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3287 | ObjectType); |
| 3288 | if (!NNS) |
| 3289 | return QualType(); |
| 3290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3292 | QualType NamedT; |
| 3293 | // FIXME: this test is meant to workaround a problem (failing assertion) |
| 3294 | // occurring if directly executing the code in the else branch. |
| 3295 | if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) { |
| 3296 | TemplateSpecializationTypeLoc OldNamedTL |
| 3297 | = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc()); |
| 3298 | const TemplateSpecializationType* OldTST |
Jim Grosbach | 9cbb4d8 | 2010-05-19 23:53:08 +0000 | [diff] [blame] | 3299 | = OldNamedTL.getType()->template getAs<TemplateSpecializationType>(); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3300 | NamedT = TransformTemplateSpecializationType(OldTST, ObjectType); |
| 3301 | if (NamedT.isNull()) |
| 3302 | return QualType(); |
| 3303 | TemplateSpecializationTypeLoc NewNamedTL |
| 3304 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3305 | NewNamedTL.copy(OldNamedTL); |
| 3306 | } |
| 3307 | else { |
| 3308 | NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 3309 | if (NamedT.isNull()) |
| 3310 | return QualType(); |
| 3311 | } |
Daniel Dunbar | a63db84 | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 3312 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3313 | QualType Result = TL.getType(); |
| 3314 | if (getDerived().AlwaysRebuild() || |
| 3315 | NNS != T->getQualifier() || |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3316 | NamedT != T->getNamedType()) { |
| 3317 | Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3318 | if (Result.isNull()) |
| 3319 | return QualType(); |
| 3320 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3321 | |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3322 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3323 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3324 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3325 | |
| 3326 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | |
| 3329 | template<typename Derived> |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3330 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3331 | DependentNameTypeLoc TL, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3332 | QualType ObjectType) { |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3333 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3335 | NestedNameSpecifier *NNS |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3336 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3337 | TL.getQualifierRange(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3338 | ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3339 | if (!NNS) |
| 3340 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3342 | QualType Result |
| 3343 | = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3344 | T->getIdentifier(), |
| 3345 | TL.getKeywordLoc(), |
| 3346 | TL.getQualifierRange(), |
| 3347 | TL.getNameLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3348 | if (Result.isNull()) |
| 3349 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3350 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3351 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 3352 | QualType NamedT = ElabT->getNamedType(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3353 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 3354 | |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3355 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3356 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3357 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3358 | } else { |
Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3359 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 3360 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3361 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3362 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3363 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3364 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3366 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3367 | template<typename Derived> |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3368 | QualType TreeTransform<Derived>:: |
| 3369 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 3370 | DependentTemplateSpecializationTypeLoc TL, |
| 3371 | QualType ObjectType) { |
| 3372 | DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 3373 | |
| 3374 | NestedNameSpecifier *NNS |
| 3375 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3376 | TL.getQualifierRange(), |
| 3377 | ObjectType); |
| 3378 | if (!NNS) |
| 3379 | return QualType(); |
| 3380 | |
| 3381 | TemplateArgumentListInfo NewTemplateArgs; |
| 3382 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3383 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3384 | |
| 3385 | for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) { |
| 3386 | TemplateArgumentLoc Loc; |
| 3387 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc)) |
| 3388 | return QualType(); |
| 3389 | NewTemplateArgs.addArgument(Loc); |
| 3390 | } |
| 3391 | |
| 3392 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| 3393 | T->getKeyword(), |
| 3394 | NNS, |
| 3395 | T->getIdentifier(), |
| 3396 | TL.getNameLoc(), |
| 3397 | NewTemplateArgs); |
| 3398 | if (Result.isNull()) |
| 3399 | return QualType(); |
| 3400 | |
| 3401 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 3402 | QualType NamedT = ElabT->getNamedType(); |
| 3403 | |
| 3404 | // Copy information relevant to the template specialization. |
| 3405 | TemplateSpecializationTypeLoc NamedTL |
| 3406 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3407 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3408 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3409 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3410 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 3411 | |
| 3412 | // Copy information relevant to the elaborated type. |
| 3413 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3414 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3415 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3416 | } else { |
Douglas Gregor | e2872d0 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 3417 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 3418 | TLB.pushFullCopy(NewTL); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3419 | } |
| 3420 | return Result; |
| 3421 | } |
| 3422 | |
| 3423 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3424 | QualType |
| 3425 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3426 | ObjCInterfaceTypeLoc TL, |
| 3427 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3428 | // ObjCInterfaceType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3429 | TLB.pushFullCopy(TL); |
| 3430 | return TL.getType(); |
| 3431 | } |
| 3432 | |
| 3433 | template<typename Derived> |
| 3434 | QualType |
| 3435 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 3436 | ObjCObjectTypeLoc TL, |
| 3437 | QualType ObjectType) { |
| 3438 | // ObjCObjectType is never dependent. |
| 3439 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3440 | return TL.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | |
| 3443 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3444 | QualType |
| 3445 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3446 | ObjCObjectPointerTypeLoc TL, |
| 3447 | QualType ObjectType) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3448 | // ObjCObjectPointerType is never dependent. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3449 | TLB.pushFullCopy(TL); |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3450 | return TL.getType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3453 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3454 | // Statement transformation |
| 3455 | //===----------------------------------------------------------------------===// |
| 3456 | template<typename Derived> |
| 3457 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3459 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | template<typename Derived> |
| 3463 | Sema::OwningStmtResult |
| 3464 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3465 | return getDerived().TransformCompoundStmt(S, false); |
| 3466 | } |
| 3467 | |
| 3468 | template<typename Derived> |
| 3469 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3470 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3471 | bool IsStmtExpr) { |
| 3472 | bool SubStmtChanged = false; |
| 3473 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3474 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3475 | B != BEnd; ++B) { |
| 3476 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3477 | if (Result.isInvalid()) |
| 3478 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3480 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3481 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3483 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3484 | if (!getDerived().AlwaysRebuild() && |
| 3485 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3487 | |
| 3488 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3489 | move_arg(Statements), |
| 3490 | S->getRBracLoc(), |
| 3491 | IsStmtExpr); |
| 3492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3493 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3494 | template<typename Derived> |
| 3495 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3496 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3497 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3498 | { |
| 3499 | // The case value expressions are not potentially evaluated. |
| 3500 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3501 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3502 | // Transform the left-hand case value. |
| 3503 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3504 | if (LHS.isInvalid()) |
| 3505 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3507 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3508 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3509 | if (RHS.isInvalid()) |
| 3510 | return SemaRef.StmtError(); |
| 3511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3512 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3513 | // Build the case statement. |
| 3514 | // Case statements are always rebuilt so that they will attached to their |
| 3515 | // transformed switch statement. |
| 3516 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3517 | move(LHS), |
| 3518 | S->getEllipsisLoc(), |
| 3519 | move(RHS), |
| 3520 | S->getColonLoc()); |
| 3521 | if (Case.isInvalid()) |
| 3522 | return SemaRef.StmtError(); |
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 | // Transform the statement following the case |
| 3525 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3526 | if (SubStmt.isInvalid()) |
| 3527 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3529 | // Attach the body to the case statement |
| 3530 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3531 | } |
| 3532 | |
| 3533 | template<typename Derived> |
| 3534 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | // Transform the statement following the default case |
| 3537 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3538 | if (SubStmt.isInvalid()) |
| 3539 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3541 | // Default statements are always rebuilt |
| 3542 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3543 | move(SubStmt)); |
| 3544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3546 | template<typename Derived> |
| 3547 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3549 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3550 | if (SubStmt.isInvalid()) |
| 3551 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3553 | // FIXME: Pass the real colon location in. |
| 3554 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3555 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3556 | move(SubStmt)); |
| 3557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3559 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3560 | Sema::OwningStmtResult |
| 3561 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3562 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3563 | OwningExprResult Cond(SemaRef); |
| 3564 | VarDecl *ConditionVar = 0; |
| 3565 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3566 | ConditionVar |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3567 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3568 | getDerived().TransformDefinition( |
| 3569 | S->getConditionVariable()->getLocation(), |
| 3570 | S->getConditionVariable())); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3571 | if (!ConditionVar) |
| 3572 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3573 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3574 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3575 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3576 | if (Cond.isInvalid()) |
| 3577 | return SemaRef.StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3578 | |
| 3579 | // Convert the condition to a boolean value. |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3580 | if (S->getCond()) { |
| 3581 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3582 | S->getIfLoc(), |
| 3583 | move(Cond)); |
| 3584 | if (CondE.isInvalid()) |
| 3585 | return getSema().StmtError(); |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3587 | Cond = move(CondE); |
| 3588 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3589 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3590 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3591 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3592 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3593 | return SemaRef.StmtError(); |
| 3594 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3595 | // Transform the "then" branch. |
| 3596 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3597 | if (Then.isInvalid()) |
| 3598 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3600 | // Transform the "else" branch. |
| 3601 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3602 | if (Else.isInvalid()) |
| 3603 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3605 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3606 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3607 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3608 | Then.get() == S->getThen() && |
| 3609 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | return SemaRef.Owned(S->Retain()); |
| 3611 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3612 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3613 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | template<typename Derived> |
| 3618 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3619 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3620 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3621 | OwningExprResult Cond(SemaRef); |
| 3622 | VarDecl *ConditionVar = 0; |
| 3623 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3624 | ConditionVar |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3625 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3626 | getDerived().TransformDefinition( |
| 3627 | S->getConditionVariable()->getLocation(), |
| 3628 | S->getConditionVariable())); |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3629 | if (!ConditionVar) |
| 3630 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3631 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3632 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3633 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3634 | if (Cond.isInvalid()) |
| 3635 | return SemaRef.StmtError(); |
| 3636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3638 | // Rebuild the switch statement. |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3639 | OwningStmtResult Switch |
| 3640 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3641 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3642 | if (Switch.isInvalid()) |
| 3643 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3644 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3645 | // Transform the body of the switch statement. |
| 3646 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3647 | if (Body.isInvalid()) |
| 3648 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3650 | // Complete the switch statement. |
| 3651 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3652 | move(Body)); |
| 3653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3655 | template<typename Derived> |
| 3656 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3658 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3659 | OwningExprResult Cond(SemaRef); |
| 3660 | VarDecl *ConditionVar = 0; |
| 3661 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3662 | ConditionVar |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3663 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3664 | getDerived().TransformDefinition( |
| 3665 | S->getConditionVariable()->getLocation(), |
| 3666 | S->getConditionVariable())); |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3667 | if (!ConditionVar) |
| 3668 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3669 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3670 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3671 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3672 | if (Cond.isInvalid()) |
| 3673 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3674 | |
| 3675 | if (S->getCond()) { |
| 3676 | // Convert the condition to a boolean value. |
| 3677 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3678 | S->getWhileLoc(), |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3679 | move(Cond)); |
| 3680 | if (CondE.isInvalid()) |
| 3681 | return getSema().StmtError(); |
| 3682 | Cond = move(CondE); |
| 3683 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3686 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3687 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3688 | return SemaRef.StmtError(); |
| 3689 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3690 | // Transform the body |
| 3691 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3692 | if (Body.isInvalid()) |
| 3693 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3695 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3696 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3697 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3701 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3702 | ConditionVar, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3704 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3705 | template<typename Derived> |
| 3706 | Sema::OwningStmtResult |
| 3707 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3708 | // Transform the body |
| 3709 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3710 | if (Body.isInvalid()) |
| 3711 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3713 | // Transform the condition |
| 3714 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3715 | if (Cond.isInvalid()) |
| 3716 | return SemaRef.StmtError(); |
| 3717 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3718 | if (!getDerived().AlwaysRebuild() && |
| 3719 | Cond.get() == S->getCond() && |
| 3720 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | return SemaRef.Owned(S->Retain()); |
| 3722 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3723 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3724 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3725 | S->getRParenLoc()); |
| 3726 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3728 | template<typename Derived> |
| 3729 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3731 | // Transform the initialization statement |
| 3732 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3733 | if (Init.isInvalid()) |
| 3734 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3735 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3736 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3737 | OwningExprResult Cond(SemaRef); |
| 3738 | VarDecl *ConditionVar = 0; |
| 3739 | if (S->getConditionVariable()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3740 | ConditionVar |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3741 | = cast_or_null<VarDecl>( |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3742 | getDerived().TransformDefinition( |
| 3743 | S->getConditionVariable()->getLocation(), |
| 3744 | S->getConditionVariable())); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3745 | if (!ConditionVar) |
| 3746 | return SemaRef.StmtError(); |
| 3747 | } else { |
| 3748 | Cond = getDerived().TransformExpr(S->getCond()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3749 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3750 | if (Cond.isInvalid()) |
| 3751 | return SemaRef.StmtError(); |
Douglas Gregor | afa0fef | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3752 | |
| 3753 | if (S->getCond()) { |
| 3754 | // Convert the condition to a boolean value. |
| 3755 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3756 | S->getForLoc(), |
| 3757 | move(Cond)); |
| 3758 | if (CondE.isInvalid()) |
| 3759 | return getSema().StmtError(); |
| 3760 | |
| 3761 | Cond = move(CondE); |
| 3762 | } |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3763 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3765 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3766 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3767 | return SemaRef.StmtError(); |
| 3768 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3769 | // Transform the increment |
| 3770 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3771 | if (Inc.isInvalid()) |
| 3772 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3774 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3775 | if (S->getInc() && !FullInc->get()) |
| 3776 | return SemaRef.StmtError(); |
| 3777 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3778 | // Transform the body |
| 3779 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3780 | if (Body.isInvalid()) |
| 3781 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3783 | if (!getDerived().AlwaysRebuild() && |
| 3784 | Init.get() == S->getInit() && |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3785 | FullCond->get() == S->getCond() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3786 | Inc.get() == S->getInc() && |
| 3787 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | return SemaRef.Owned(S->Retain()); |
| 3789 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3790 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | eaa18e4 | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3791 | move(Init), FullCond, ConditionVar, |
| 3792 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3796 | Sema::OwningStmtResult |
| 3797 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3798 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3800 | S->getLabel()); |
| 3801 | } |
| 3802 | |
| 3803 | template<typename Derived> |
| 3804 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3806 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3807 | if (Target.isInvalid()) |
| 3808 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3810 | if (!getDerived().AlwaysRebuild() && |
| 3811 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3812 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3813 | |
| 3814 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3815 | move(Target)); |
| 3816 | } |
| 3817 | |
| 3818 | template<typename Derived> |
| 3819 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3820 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3821 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3822 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3823 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3824 | template<typename Derived> |
| 3825 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3826 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3827 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3830 | template<typename Derived> |
| 3831 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3833 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3834 | if (Result.isInvalid()) |
| 3835 | return SemaRef.StmtError(); |
| 3836 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3838 | // to tell whether the return type of the function has changed. |
| 3839 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3842 | template<typename Derived> |
| 3843 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3845 | bool DeclChanged = false; |
| 3846 | llvm::SmallVector<Decl *, 4> Decls; |
| 3847 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3848 | D != DEnd; ++D) { |
Douglas Gregor | aac571c | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3849 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3850 | *D); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3851 | if (!Transformed) |
| 3852 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3853 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3854 | if (Transformed != *D) |
| 3855 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3856 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3857 | Decls.push_back(Transformed); |
| 3858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3859 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3860 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3861 | return SemaRef.Owned(S->Retain()); |
| 3862 | |
| 3863 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3864 | S->getStartLoc(), S->getEndLoc()); |
| 3865 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3867 | template<typename Derived> |
| 3868 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3869 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3870 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | template<typename Derived> |
| 3875 | Sema::OwningStmtResult |
| 3876 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
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 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3879 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3880 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3881 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3882 | OwningExprResult AsmString(SemaRef); |
| 3883 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3884 | |
| 3885 | bool ExprsChanged = false; |
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 | // Go through the outputs. |
| 3888 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3889 | Names.push_back(S->getOutputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3890 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3891 | // No need to transform the constraint literal. |
| 3892 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3893 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3894 | // Transform the output expr. |
| 3895 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3896 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3897 | if (Result.isInvalid()) |
| 3898 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3899 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3900 | ExprsChanged |= Result.get() != OutputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3901 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3902 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3903 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3904 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3905 | // Go through the inputs. |
| 3906 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3907 | Names.push_back(S->getInputIdentifier(I)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3908 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3909 | // No need to transform the constraint literal. |
| 3910 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3911 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3912 | // Transform the input expr. |
| 3913 | Expr *InputExpr = S->getInputExpr(I); |
| 3914 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3915 | if (Result.isInvalid()) |
| 3916 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3917 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3918 | ExprsChanged |= Result.get() != InputExpr; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3919 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3920 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3921 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3922 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3923 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3924 | return SemaRef.Owned(S->Retain()); |
| 3925 | |
| 3926 | // Go through the clobbers. |
| 3927 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3928 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3929 | |
| 3930 | // No need to transform the asm string literal. |
| 3931 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3932 | |
| 3933 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3934 | S->isSimple(), |
| 3935 | S->isVolatile(), |
| 3936 | S->getNumOutputs(), |
| 3937 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3938 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3939 | move_arg(Constraints), |
| 3940 | move_arg(Exprs), |
| 3941 | move(AsmString), |
| 3942 | move_arg(Clobbers), |
| 3943 | S->getRParenLoc(), |
| 3944 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | |
| 3948 | template<typename Derived> |
| 3949 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3951 | // Transform the body of the @try. |
| 3952 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3953 | if (TryBody.isInvalid()) |
| 3954 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3956 | // Transform the @catch statements (if present). |
| 3957 | bool AnyCatchChanged = false; |
| 3958 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3959 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3960 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3961 | if (Catch.isInvalid()) |
| 3962 | return SemaRef.StmtError(); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3963 | if (Catch.get() != S->getCatchStmt(I)) |
| 3964 | AnyCatchChanged = true; |
| 3965 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3966 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3967 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3968 | // Transform the @finally statement (if present). |
| 3969 | OwningStmtResult Finally(SemaRef); |
| 3970 | if (S->getFinallyStmt()) { |
| 3971 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3972 | if (Finally.isInvalid()) |
| 3973 | return SemaRef.StmtError(); |
| 3974 | } |
| 3975 | |
| 3976 | // If nothing changed, just retain this statement. |
| 3977 | if (!getDerived().AlwaysRebuild() && |
| 3978 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3979 | !AnyCatchChanged && |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3980 | Finally.get() == S->getFinallyStmt()) |
| 3981 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3982 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3983 | // Build a new statement. |
| 3984 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3985 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3987 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3988 | template<typename Derived> |
| 3989 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3990 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3991 | // Transform the @catch parameter, if there is one. |
| 3992 | VarDecl *Var = 0; |
| 3993 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3994 | TypeSourceInfo *TSInfo = 0; |
| 3995 | if (FromVar->getTypeSourceInfo()) { |
| 3996 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3997 | if (!TSInfo) |
| 3998 | return SemaRef.StmtError(); |
| 3999 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4001 | QualType T; |
| 4002 | if (TSInfo) |
| 4003 | T = TSInfo->getType(); |
| 4004 | else { |
| 4005 | T = getDerived().TransformType(FromVar->getType()); |
| 4006 | if (T.isNull()) |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4007 | return SemaRef.StmtError(); |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4008 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4009 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4010 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 4011 | if (!Var) |
| 4012 | return SemaRef.StmtError(); |
| 4013 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4014 | |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4015 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 4016 | if (Body.isInvalid()) |
| 4017 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4018 | |
| 4019 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4020 | S->getRParenLoc(), |
| 4021 | Var, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4024 | template<typename Derived> |
| 4025 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4026 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4027 | // Transform the body. |
| 4028 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 4029 | if (Body.isInvalid()) |
| 4030 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4032 | // If nothing changed, just retain this statement. |
| 4033 | if (!getDerived().AlwaysRebuild() && |
| 4034 | Body.get() == S->getFinallyBody()) |
| 4035 | return SemaRef.Owned(S->Retain()); |
| 4036 | |
| 4037 | // Build a new statement. |
| 4038 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 4039 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4042 | template<typename Derived> |
| 4043 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4045 | OwningExprResult Operand(SemaRef); |
| 4046 | if (S->getThrowExpr()) { |
| 4047 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 4048 | if (Operand.isInvalid()) |
| 4049 | return getSema().StmtError(); |
| 4050 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4052 | if (!getDerived().AlwaysRebuild() && |
| 4053 | Operand.get() == S->getThrowExpr()) |
| 4054 | return getSema().Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4055 | |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4056 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4059 | template<typename Derived> |
| 4060 | Sema::OwningStmtResult |
| 4061 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4062 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4063 | // Transform the object we are locking. |
| 4064 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 4065 | if (Object.isInvalid()) |
| 4066 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4067 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4068 | // Transform the body. |
| 4069 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 4070 | if (Body.isInvalid()) |
| 4071 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4072 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4073 | // If nothing change, just retain the current statement. |
| 4074 | if (!getDerived().AlwaysRebuild() && |
| 4075 | Object.get() == S->getSynchExpr() && |
| 4076 | Body.get() == S->getSynchBody()) |
| 4077 | return SemaRef.Owned(S->Retain()); |
| 4078 | |
| 4079 | // Build a new statement. |
| 4080 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 4081 | move(Object), move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | template<typename Derived> |
| 4085 | Sema::OwningStmtResult |
| 4086 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | ObjCForCollectionStmt *S) { |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4088 | // Transform the element statement. |
| 4089 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 4090 | if (Element.isInvalid()) |
| 4091 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4093 | // Transform the collection expression. |
| 4094 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 4095 | if (Collection.isInvalid()) |
| 4096 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4097 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4098 | // Transform the body. |
| 4099 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 4100 | if (Body.isInvalid()) |
| 4101 | return SemaRef.StmtError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4102 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4103 | // If nothing changed, just retain this statement. |
| 4104 | if (!getDerived().AlwaysRebuild() && |
| 4105 | Element.get() == S->getElement() && |
| 4106 | Collection.get() == S->getCollection() && |
| 4107 | Body.get() == S->getBody()) |
| 4108 | return SemaRef.Owned(S->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4110 | // Build a new statement. |
| 4111 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4112 | /*FIXME:*/S->getForLoc(), |
| 4113 | move(Element), |
| 4114 | move(Collection), |
| 4115 | S->getRParenLoc(), |
| 4116 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | |
| 4120 | template<typename Derived> |
| 4121 | Sema::OwningStmtResult |
| 4122 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4123 | // Transform the exception declaration, if any. |
| 4124 | VarDecl *Var = 0; |
| 4125 | if (S->getExceptionDecl()) { |
| 4126 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4127 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4128 | ExceptionDecl->getDeclName()); |
| 4129 | |
| 4130 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4131 | if (T.isNull()) |
| 4132 | return SemaRef.StmtError(); |
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 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4135 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4136 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4137 | ExceptionDecl->getIdentifier(), |
| 4138 | ExceptionDecl->getLocation(), |
| 4139 | /*FIXME: Inaccurate*/ |
| 4140 | SourceRange(ExceptionDecl->getLocation())); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 4141 | if (!Var || Var->isInvalidDecl()) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4142 | return SemaRef.StmtError(); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4143 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4144 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4145 | // Transform the actual exception handler. |
| 4146 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 4147 | if (Handler.isInvalid()) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4148 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4150 | if (!getDerived().AlwaysRebuild() && |
| 4151 | !Var && |
| 4152 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4154 | |
| 4155 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4156 | Var, |
| 4157 | move(Handler)); |
| 4158 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4159 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4160 | template<typename Derived> |
| 4161 | Sema::OwningStmtResult |
| 4162 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4163 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4164 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4165 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4166 | if (TryBlock.isInvalid()) |
| 4167 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4169 | // Transform the handlers. |
| 4170 | bool HandlerChanged = false; |
| 4171 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4172 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4174 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4175 | if (Handler.isInvalid()) |
| 4176 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4178 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4179 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4182 | if (!getDerived().AlwaysRebuild() && |
| 4183 | TryBlock.get() == S->getTryBlock() && |
| 4184 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4185 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4186 | |
| 4187 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4189 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4190 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4191 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | // Expression transformation |
| 4193 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4194 | template<typename Derived> |
| 4195 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4196 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
| 4200 | template<typename Derived> |
| 4201 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4202 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4203 | NestedNameSpecifier *Qualifier = 0; |
| 4204 | if (E->getQualifier()) { |
| 4205 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4206 | E->getQualifierRange()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4207 | if (!Qualifier) |
| 4208 | return SemaRef.ExprError(); |
| 4209 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4210 | |
| 4211 | ValueDecl *ND |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4212 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4213 | E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | if (!ND) |
| 4215 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4217 | DeclarationNameInfo NameInfo |
| 4218 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 4219 | if (!NameInfo.getName()) |
| 4220 | return SemaRef.ExprError(); |
| 4221 | |
| 4222 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4223 | Qualifier == E->getQualifier() && |
| 4224 | ND == E->getDecl() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4225 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4226 | !E->hasExplicitTemplateArgumentList()) { |
| 4227 | |
| 4228 | // Mark it referenced in the new context regardless. |
| 4229 | // FIXME: this is a bit instantiation-specific. |
| 4230 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4231 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4232 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4233 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4234 | |
| 4235 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4236 | if (E->hasExplicitTemplateArgumentList()) { |
| 4237 | TemplateArgs = &TransArgs; |
| 4238 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4239 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4240 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4241 | TemplateArgumentLoc Loc; |
| 4242 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4243 | return SemaRef.ExprError(); |
| 4244 | TransArgs.addArgument(Loc); |
| 4245 | } |
| 4246 | } |
| 4247 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4248 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4249 | ND, NameInfo, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4251 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4252 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4254 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4258 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4260 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4265 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4266 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4267 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4269 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4270 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4272 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4273 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4276 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4277 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4278 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | return SemaRef.Owned(E->Retain()); |
| 4280 | } |
| 4281 | |
| 4282 | template<typename Derived> |
| 4283 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4284 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4286 | if (SubExpr.isInvalid()) |
| 4287 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | return SemaRef.Owned(E->Retain()); |
| 4291 | |
| 4292 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4293 | E->getRParen()); |
| 4294 | } |
| 4295 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 | template<typename Derived> |
| 4297 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4298 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4299 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4300 | if (SubExpr.isInvalid()) |
| 4301 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4302 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4303 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4304 | return SemaRef.Owned(E->Retain()); |
| 4305 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4307 | E->getOpcode(), |
| 4308 | move(SubExpr)); |
| 4309 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4310 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | Sema::OwningExprResult |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4313 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4314 | // Transform the type. |
| 4315 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4316 | if (!Type) |
| 4317 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4319 | // Transform all of the components into components similar to what the |
| 4320 | // parser uses. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4321 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4322 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4323 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4324 | // template code that we don't care. |
| 4325 | bool ExprChanged = false; |
| 4326 | typedef Action::OffsetOfComponent Component; |
| 4327 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4328 | llvm::SmallVector<Component, 4> Components; |
| 4329 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4330 | const Node &ON = E->getComponent(I); |
| 4331 | Component Comp; |
Douglas Gregor | 72be24f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4332 | Comp.isBrackets = true; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4333 | Comp.LocStart = ON.getRange().getBegin(); |
| 4334 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4335 | switch (ON.getKind()) { |
| 4336 | case Node::Array: { |
| 4337 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4338 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4339 | if (Index.isInvalid()) |
| 4340 | return getSema().ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4341 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4342 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4343 | Comp.isBrackets = true; |
| 4344 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4345 | break; |
| 4346 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4348 | case Node::Field: |
| 4349 | case Node::Identifier: |
| 4350 | Comp.isBrackets = false; |
| 4351 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | 29d2fd5 | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4352 | if (!Comp.U.IdentInfo) |
| 4353 | continue; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4355 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4356 | |
Douglas Gregor | cc8a5d5 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4357 | case Node::Base: |
| 4358 | // Will be recomputed during the rebuild. |
| 4359 | continue; |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4360 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4361 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4362 | Components.push_back(Comp); |
| 4363 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4364 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4365 | // If nothing changed, retain the existing expression. |
| 4366 | if (!getDerived().AlwaysRebuild() && |
| 4367 | Type == E->getTypeSourceInfo() && |
| 4368 | !ExprChanged) |
| 4369 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4370 | |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4371 | // Build a new offsetof expression. |
| 4372 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4373 | Components.data(), Components.size(), |
| 4374 | E->getRParenLoc()); |
| 4375 | } |
| 4376 | |
| 4377 | template<typename Derived> |
| 4378 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4379 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4381 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4382 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4383 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4384 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4385 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4386 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4387 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4390 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | E->getSourceRange()); |
| 4393 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4395 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4397 | // C++0x [expr.sizeof]p1: |
| 4398 | // The operand is either an expression, which is an unevaluated operand |
| 4399 | // [...] |
| 4400 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4403 | if (SubExpr.isInvalid()) |
| 4404 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4407 | return SemaRef.Owned(E->Retain()); |
| 4408 | } |
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().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4411 | E->isSizeOf(), |
| 4412 | E->getSourceRange()); |
| 4413 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4415 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4417 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4418 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4419 | if (LHS.isInvalid()) |
| 4420 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4421 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4422 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4423 | if (RHS.isInvalid()) |
| 4424 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
| 4426 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | if (!getDerived().AlwaysRebuild() && |
| 4428 | LHS.get() == E->getLHS() && |
| 4429 | RHS.get() == E->getRHS()) |
| 4430 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4431 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4433 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4434 | move(RHS), |
| 4435 | E->getRBracketLoc()); |
| 4436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | |
| 4438 | template<typename Derived> |
| 4439 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4440 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4441 | // Transform the callee. |
| 4442 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4443 | if (Callee.isInvalid()) |
| 4444 | return SemaRef.ExprError(); |
| 4445 | |
| 4446 | // Transform arguments. |
| 4447 | bool ArgChanged = false; |
| 4448 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4449 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4450 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4451 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4452 | if (Arg.isInvalid()) |
| 4453 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4454 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4455 | // FIXME: Wrong source location information for the ','. |
| 4456 | FakeCommaLocs.push_back( |
| 4457 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | |
| 4459 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | Args.push_back(Arg.takeAs<Expr>()); |
| 4461 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4462 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4463 | if (!getDerived().AlwaysRebuild() && |
| 4464 | Callee.get() == E->getCallee() && |
| 4465 | !ArgChanged) |
| 4466 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4471 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4472 | move_arg(Args), |
| 4473 | FakeCommaLocs.data(), |
| 4474 | E->getRParenLoc()); |
| 4475 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | |
| 4477 | template<typename Derived> |
| 4478 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4479 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4481 | if (Base.isInvalid()) |
| 4482 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4484 | NestedNameSpecifier *Qualifier = 0; |
| 4485 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4487 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4488 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4489 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4490 | return SemaRef.ExprError(); |
| 4491 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4493 | ValueDecl *Member |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4494 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4495 | E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4496 | if (!Member) |
| 4497 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4498 | |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4499 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4500 | if (FoundDecl == E->getMemberDecl()) { |
| 4501 | FoundDecl = Member; |
| 4502 | } else { |
| 4503 | FoundDecl = cast_or_null<NamedDecl>( |
| 4504 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4505 | if (!FoundDecl) |
| 4506 | return SemaRef.ExprError(); |
| 4507 | } |
| 4508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | if (!getDerived().AlwaysRebuild() && |
| 4510 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4511 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4512 | Member == E->getMemberDecl() && |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4513 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4514 | !E->hasExplicitTemplateArgumentList()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4515 | |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4516 | // Mark it referenced in the new context regardless. |
| 4517 | // FIXME: this is a bit instantiation-specific. |
| 4518 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4520 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4522 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4523 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4524 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4525 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4526 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4527 | TemplateArgumentLoc Loc; |
| 4528 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4529 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4530 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4531 | } |
| 4532 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | // FIXME: Bogus source location for the operator |
| 4535 | SourceLocation FakeOperatorLoc |
| 4536 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4537 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4538 | // FIXME: to do this check properly, we will need to preserve the |
| 4539 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4540 | // base (and therefore couldn't do the check) and a |
| 4541 | // nested-name-qualifier (and therefore could do the lookup). |
| 4542 | NamedDecl *FirstQualifierInScope = 0; |
| 4543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4544 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4545 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4546 | Qualifier, |
| 4547 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4548 | E->getMemberNameInfo(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4549 | Member, |
John McCall | 6bb8017 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4550 | FoundDecl, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4551 | (E->hasExplicitTemplateArgumentList() |
| 4552 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4553 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4554 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4555 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4556 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4558 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4560 | if (LHS.isInvalid()) |
| 4561 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4563 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4564 | if (RHS.isInvalid()) |
| 4565 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | if (!getDerived().AlwaysRebuild() && |
| 4568 | LHS.get() == E->getLHS() && |
| 4569 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | return SemaRef.Owned(E->Retain()); |
| 4571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4573 | move(LHS), move(RHS)); |
| 4574 | } |
| 4575 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | Sema::OwningExprResult |
| 4578 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4579 | CompoundAssignOperator *E) { |
| 4580 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4582 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4583 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4585 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4586 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4587 | if (Cond.isInvalid()) |
| 4588 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4590 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4591 | if (LHS.isInvalid()) |
| 4592 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4594 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4595 | if (RHS.isInvalid()) |
| 4596 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4597 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4598 | if (!getDerived().AlwaysRebuild() && |
| 4599 | Cond.get() == E->getCond() && |
| 4600 | LHS.get() == E->getLHS() && |
| 4601 | RHS.get() == E->getRHS()) |
| 4602 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | |
| 4604 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4605 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4607 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4608 | move(RHS)); |
| 4609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4610 | |
| 4611 | template<typename Derived> |
| 4612 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4613 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4614 | // Implicit casts are eliminated during transformation, since they |
| 4615 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4616 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | } |
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 | template<typename Derived> |
| 4620 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4621 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4622 | TypeSourceInfo *OldT; |
| 4623 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4624 | { |
| 4625 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4626 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4627 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4628 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4629 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4630 | OldT = E->getTypeInfoAsWritten(); |
| 4631 | NewT = getDerived().TransformType(OldT); |
| 4632 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | return SemaRef.ExprError(); |
| 4634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4635 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4636 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4637 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | if (SubExpr.isInvalid()) |
| 4639 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4642 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | return SemaRef.Owned(E->Retain()); |
| 4645 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4646 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4647 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4648 | E->getRParenLoc(), |
| 4649 | move(SubExpr)); |
| 4650 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4651 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4652 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4654 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4655 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4656 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4657 | if (!NewT) |
| 4658 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4660 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4661 | if (Init.isInvalid()) |
| 4662 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4663 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4664 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4665 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4669 | // Note: the expression type doesn't necessarily match the |
| 4670 | // type-as-written, but that's okay, because it should always be |
| 4671 | // derivable from the initializer. |
| 4672 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4673 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4674 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4675 | move(Init)); |
| 4676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | template<typename Derived> |
| 4679 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4680 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4681 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4682 | if (Base.isInvalid()) |
| 4683 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4684 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | if (!getDerived().AlwaysRebuild() && |
| 4686 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | return SemaRef.Owned(E->Retain()); |
| 4688 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4690 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4691 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4692 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4693 | E->getAccessorLoc(), |
| 4694 | E->getAccessor()); |
| 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> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4699 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4701 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4703 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4704 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4705 | if (Init.isInvalid()) |
| 4706 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4707 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4708 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4709 | Inits.push_back(Init.takeAs<Expr>()); |
| 4710 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4711 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4712 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4713 | return SemaRef.Owned(E->Retain()); |
| 4714 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4715 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4716 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | template<typename Derived> |
| 4720 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4721 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4724 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4726 | if (Init.isInvalid()) |
| 4727 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4728 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4729 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4730 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4731 | bool ExprChanged = false; |
| 4732 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4733 | DEnd = E->designators_end(); |
| 4734 | D != DEnd; ++D) { |
| 4735 | if (D->isFieldDesignator()) { |
| 4736 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4737 | D->getDotLoc(), |
| 4738 | D->getFieldLoc())); |
| 4739 | continue; |
| 4740 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4741 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4742 | if (D->isArrayDesignator()) { |
| 4743 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4744 | if (Index.isInvalid()) |
| 4745 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
| 4747 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4751 | ArrayExprs.push_back(Index.release()); |
| 4752 | continue; |
| 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 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4756 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4757 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4758 | if (Start.isInvalid()) |
| 4759 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4761 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4762 | if (End.isInvalid()) |
| 4763 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | |
| 4765 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4766 | End.get(), |
| 4767 | D->getLBracketLoc(), |
| 4768 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4769 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4770 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4771 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | ArrayExprs.push_back(Start.release()); |
| 4774 | ArrayExprs.push_back(End.release()); |
| 4775 | } |
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 | Init.get() == E->getInit() && |
| 4779 | !ExprChanged) |
| 4780 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4781 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4782 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4783 | E->getEqualOrColonLoc(), |
| 4784 | E->usesGNUSyntax(), move(Init)); |
| 4785 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4789 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4790 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4791 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4792 | |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4793 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4794 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4795 | QualType T = getDerived().TransformType(E->getType()); |
| 4796 | if (T.isNull()) |
| 4797 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4798 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | if (!getDerived().AlwaysRebuild() && |
| 4800 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | return SemaRef.Owned(E->Retain()); |
| 4802 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4803 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4804 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4805 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4806 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4807 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4808 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 4809 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 4810 | if (!TInfo) |
| 4811 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4812 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4813 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4814 | if (SubExpr.isInvalid()) |
| 4815 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 4818 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4819 | SubExpr.get() == E->getSubExpr()) |
| 4820 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
Abramo Bagnara | 2cad900 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 4823 | TInfo, E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4824 | } |
| 4825 | |
| 4826 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4828 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4829 | bool ArgumentChanged = false; |
| 4830 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4831 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4832 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4833 | if (Init.isInvalid()) |
| 4834 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4835 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4836 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4837 | Inits.push_back(Init.takeAs<Expr>()); |
| 4838 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4840 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4841 | move_arg(Inits), |
| 4842 | E->getRParenLoc()); |
| 4843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4845 | /// \brief Transform an address-of-label expression. |
| 4846 | /// |
| 4847 | /// By default, the transformation of an address-of-label expression always |
| 4848 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4849 | /// the corresponding label statement by semantic analysis. |
| 4850 | template<typename Derived> |
| 4851 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4852 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4853 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4854 | E->getLabel()); |
| 4855 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4856 | |
| 4857 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4858 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4859 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4861 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4862 | if (SubStmt.isInvalid()) |
| 4863 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4864 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4865 | if (!getDerived().AlwaysRebuild() && |
| 4866 | SubStmt.get() == E->getSubStmt()) |
| 4867 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4868 | |
| 4869 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4870 | move(SubStmt), |
| 4871 | E->getRParenLoc()); |
| 4872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4873 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4874 | template<typename Derived> |
| 4875 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4876 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Abramo Bagnara | 3fcb73d | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4877 | TypeSourceInfo *TInfo1; |
| 4878 | TypeSourceInfo *TInfo2; |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 4879 | |
| 4880 | TInfo1 = getDerived().TransformType(E->getArgTInfo1()); |
| 4881 | if (!TInfo1) |
| 4882 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4883 | |
Douglas Gregor | 9bcd4d4 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 4884 | TInfo2 = getDerived().TransformType(E->getArgTInfo2()); |
| 4885 | if (!TInfo2) |
| 4886 | return SemaRef.ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4887 | |
| 4888 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 3fcb73d | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4889 | TInfo1 == E->getArgTInfo1() && |
| 4890 | TInfo2 == E->getArgTInfo2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | return SemaRef.Owned(E->Retain()); |
| 4892 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4893 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
Abramo Bagnara | 3fcb73d | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4894 | TInfo1, TInfo2, |
| 4895 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4897 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4898 | template<typename Derived> |
| 4899 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4900 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4901 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4902 | if (Cond.isInvalid()) |
| 4903 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4906 | if (LHS.isInvalid()) |
| 4907 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4908 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4909 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4910 | if (RHS.isInvalid()) |
| 4911 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4912 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4913 | if (!getDerived().AlwaysRebuild() && |
| 4914 | Cond.get() == E->getCond() && |
| 4915 | LHS.get() == E->getLHS() && |
| 4916 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4917 | return SemaRef.Owned(E->Retain()); |
| 4918 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4919 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4920 | move(Cond), move(LHS), move(RHS), |
| 4921 | E->getRParenLoc()); |
| 4922 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4923 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4924 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4925 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4926 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4927 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | template<typename Derived> |
| 4931 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4932 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4933 | switch (E->getOperator()) { |
| 4934 | case OO_New: |
| 4935 | case OO_Delete: |
| 4936 | case OO_Array_New: |
| 4937 | case OO_Array_Delete: |
| 4938 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4939 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4940 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4941 | case OO_Call: { |
| 4942 | // This is a call to an object's operator(). |
| 4943 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4944 | |
| 4945 | // Transform the object itself. |
| 4946 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4947 | if (Object.isInvalid()) |
| 4948 | return SemaRef.ExprError(); |
| 4949 | |
| 4950 | // FIXME: Poor location information |
| 4951 | SourceLocation FakeLParenLoc |
| 4952 | = SemaRef.PP.getLocForEndOfToken( |
| 4953 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4954 | |
| 4955 | // Transform the call arguments. |
| 4956 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4957 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4958 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4959 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4960 | break; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4961 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4962 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4963 | if (Arg.isInvalid()) |
| 4964 | return SemaRef.ExprError(); |
| 4965 | |
| 4966 | // FIXME: Poor source location information. |
| 4967 | SourceLocation FakeCommaLoc |
| 4968 | = SemaRef.PP.getLocForEndOfToken( |
| 4969 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4970 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4971 | Args.push_back(Arg.release()); |
| 4972 | } |
| 4973 | |
| 4974 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4975 | move_arg(Args), |
| 4976 | FakeCommaLocs.data(), |
| 4977 | E->getLocEnd()); |
| 4978 | } |
| 4979 | |
| 4980 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4981 | case OO_##Name: |
| 4982 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4983 | #include "clang/Basic/OperatorKinds.def" |
| 4984 | case OO_Subscript: |
| 4985 | // Handled below. |
| 4986 | break; |
| 4987 | |
| 4988 | case OO_Conditional: |
| 4989 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4990 | return SemaRef.ExprError(); |
| 4991 | |
| 4992 | case OO_None: |
| 4993 | case NUM_OVERLOADED_OPERATORS: |
| 4994 | llvm_unreachable("not an overloaded operator?"); |
| 4995 | return SemaRef.ExprError(); |
| 4996 | } |
| 4997 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4998 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4999 | if (Callee.isInvalid()) |
| 5000 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5001 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5002 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5003 | if (First.isInvalid()) |
| 5004 | return SemaRef.ExprError(); |
| 5005 | |
| 5006 | OwningExprResult Second(SemaRef); |
| 5007 | if (E->getNumArgs() == 2) { |
| 5008 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 5009 | if (Second.isInvalid()) |
| 5010 | return SemaRef.ExprError(); |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 5014 | Callee.get() == E->getCallee() && |
| 5015 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 5017 | return SemaRef.Owned(E->Retain()); |
| 5018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5019 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 5020 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5022 | move(First), |
| 5023 | move(Second)); |
| 5024 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5025 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5026 | template<typename Derived> |
| 5027 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5028 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5029 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5032 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5033 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5034 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5035 | TypeSourceInfo *OldT; |
| 5036 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5037 | { |
| 5038 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5039 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5040 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5041 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5042 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5043 | OldT = E->getTypeInfoAsWritten(); |
| 5044 | NewT = getDerived().TransformType(OldT); |
| 5045 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5046 | return SemaRef.ExprError(); |
| 5047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5048 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5049 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5050 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5051 | if (SubExpr.isInvalid()) |
| 5052 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5053 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5054 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5055 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5057 | return SemaRef.Owned(E->Retain()); |
| 5058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5059 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5060 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5061 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5062 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 5063 | SourceLocation FakeRParenLoc |
| 5064 | = SemaRef.PP.getLocForEndOfToken( |
| 5065 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5066 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5067 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5068 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5069 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5070 | FakeRAngleLoc, |
| 5071 | FakeRAngleLoc, |
| 5072 | move(SubExpr), |
| 5073 | FakeRParenLoc); |
| 5074 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5075 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | template<typename Derived> |
| 5077 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5078 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *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 | |
| 5082 | template<typename Derived> |
| 5083 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5084 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5085 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5086 | } |
| 5087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | template<typename Derived> |
| 5089 | Sema::OwningExprResult |
| 5090 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5091 | CXXReinterpretCastExpr *E) { |
| 5092 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | template<typename Derived> |
| 5096 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5097 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5098 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5100 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5101 | template<typename Derived> |
| 5102 | Sema::OwningExprResult |
| 5103 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5104 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5105 | TypeSourceInfo *OldT; |
| 5106 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5107 | { |
| 5108 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5110 | OldT = E->getTypeInfoAsWritten(); |
| 5111 | NewT = getDerived().TransformType(OldT); |
| 5112 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5113 | return SemaRef.ExprError(); |
| 5114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5115 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5116 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5117 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5118 | if (SubExpr.isInvalid()) |
| 5119 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5122 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5123 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | return SemaRef.Owned(E->Retain()); |
| 5125 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5126 | // FIXME: The end of the type's source range is wrong |
| 5127 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5128 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5129 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5130 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5131 | move(SubExpr), |
| 5132 | E->getRParenLoc()); |
| 5133 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5135 | template<typename Derived> |
| 5136 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5137 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5138 | if (E->isTypeOperand()) { |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5139 | TypeSourceInfo *TInfo |
| 5140 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5141 | if (!TInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5142 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5143 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5145 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5146 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5148 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5149 | E->getLocStart(), |
| 5150 | TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5151 | E->getLocEnd()); |
| 5152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5154 | // We don't know whether the expression is potentially evaluated until |
| 5155 | // after we perform semantic analysis, so the expression is potentially |
| 5156 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5157 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5158 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5159 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5160 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5161 | if (SubExpr.isInvalid()) |
| 5162 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5164 | if (!getDerived().AlwaysRebuild() && |
| 5165 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5166 | return SemaRef.Owned(E->Retain()); |
| 5167 | |
Douglas Gregor | 57fdc8a | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5168 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5169 | E->getLocStart(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5170 | move(SubExpr), |
| 5171 | E->getLocEnd()); |
| 5172 | } |
| 5173 | |
| 5174 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5176 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5177 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | template<typename Derived> |
| 5181 | Sema::OwningExprResult |
| 5182 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5183 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5184 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5187 | template<typename Derived> |
| 5188 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5189 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5190 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | QualType T = getDerived().TransformType(E->getType()); |
| 5193 | if (T.isNull()) |
| 5194 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5196 | if (!getDerived().AlwaysRebuild() && |
| 5197 | T == E->getType()) |
| 5198 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5200 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5201 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | template<typename Derived> |
| 5204 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5205 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5206 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5207 | if (SubExpr.isInvalid()) |
| 5208 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | if (!getDerived().AlwaysRebuild() && |
| 5211 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5213 | |
| 5214 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5215 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5216 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5217 | template<typename Derived> |
| 5218 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5219 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | ParmVarDecl *Param |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5221 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5222 | E->getParam())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5223 | if (!Param) |
| 5224 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5225 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5226 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | Param == E->getParam()) |
| 5228 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5229 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5230 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | template<typename Derived> |
| 5234 | Sema::OwningExprResult |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 5235 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5236 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5237 | |
| 5238 | QualType T = getDerived().TransformType(E->getType()); |
| 5239 | if (T.isNull()) |
| 5240 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5241 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5242 | if (!getDerived().AlwaysRebuild() && |
| 5243 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | return SemaRef.Owned(E->Retain()); |
| 5245 | |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 5246 | return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(), |
| 5247 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5248 | T, |
| 5249 | E->getRParenLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5251 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5252 | template<typename Derived> |
| 5253 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5254 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5255 | // Transform the type that we're allocating |
| 5256 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5257 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5258 | if (AllocType.isNull()) |
| 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 | // Transform the size of the array we're allocating (if any). |
| 5262 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5263 | if (ArraySize.isInvalid()) |
| 5264 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5265 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5266 | // Transform the placement arguments (if any). |
| 5267 | bool ArgumentChanged = false; |
| 5268 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5269 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5270 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5271 | if (Arg.isInvalid()) |
| 5272 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5273 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5274 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5275 | PlacementArgs.push_back(Arg.take()); |
| 5276 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5278 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5279 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5280 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
Douglas Gregor | ff2e4f4 | 2010-05-26 07:10:06 +0000 | [diff] [blame] | 5281 | if (getDerived().DropCallArgument(E->getConstructorArg(I))) |
| 5282 | break; |
| 5283 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5284 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5285 | if (Arg.isInvalid()) |
| 5286 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5288 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5289 | ConstructorArgs.push_back(Arg.take()); |
| 5290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5291 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5292 | // Transform constructor, new operator, and delete operator. |
| 5293 | CXXConstructorDecl *Constructor = 0; |
| 5294 | if (E->getConstructor()) { |
| 5295 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5296 | getDerived().TransformDecl(E->getLocStart(), |
| 5297 | E->getConstructor())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5298 | if (!Constructor) |
| 5299 | return SemaRef.ExprError(); |
| 5300 | } |
| 5301 | |
| 5302 | FunctionDecl *OperatorNew = 0; |
| 5303 | if (E->getOperatorNew()) { |
| 5304 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5305 | getDerived().TransformDecl(E->getLocStart(), |
| 5306 | E->getOperatorNew())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5307 | if (!OperatorNew) |
| 5308 | return SemaRef.ExprError(); |
| 5309 | } |
| 5310 | |
| 5311 | FunctionDecl *OperatorDelete = 0; |
| 5312 | if (E->getOperatorDelete()) { |
| 5313 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5314 | getDerived().TransformDecl(E->getLocStart(), |
| 5315 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5316 | if (!OperatorDelete) |
| 5317 | return SemaRef.ExprError(); |
| 5318 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5319 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5320 | if (!getDerived().AlwaysRebuild() && |
| 5321 | AllocType == E->getAllocatedType() && |
| 5322 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5323 | Constructor == E->getConstructor() && |
| 5324 | OperatorNew == E->getOperatorNew() && |
| 5325 | OperatorDelete == E->getOperatorDelete() && |
| 5326 | !ArgumentChanged) { |
| 5327 | // Mark any declarations we need as referenced. |
| 5328 | // FIXME: instantiation-specific. |
| 5329 | if (Constructor) |
| 5330 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5331 | if (OperatorNew) |
| 5332 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5333 | if (OperatorDelete) |
| 5334 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5336 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5337 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5338 | if (!ArraySize.get()) { |
| 5339 | // If no array size was specified, but the new expression was |
| 5340 | // instantiated with an array type (e.g., "new T" where T is |
| 5341 | // instantiated with "int[4]"), extract the outer bound from the |
| 5342 | // array type as our array size. We do this with constant and |
| 5343 | // dependently-sized array types. |
| 5344 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5345 | if (!ArrayT) { |
| 5346 | // Do nothing |
| 5347 | } else if (const ConstantArrayType *ConsArrayT |
| 5348 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5349 | ArraySize |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5350 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5351 | ConsArrayT->getSize(), |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5352 | SemaRef.Context.getSizeType(), |
| 5353 | /*FIXME:*/E->getLocStart())); |
| 5354 | AllocType = ConsArrayT->getElementType(); |
| 5355 | } else if (const DependentSizedArrayType *DepArrayT |
| 5356 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5357 | if (DepArrayT->getSizeExpr()) { |
| 5358 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5359 | AllocType = DepArrayT->getElementType(); |
| 5360 | } |
| 5361 | } |
| 5362 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5363 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5364 | E->isGlobalNew(), |
| 5365 | /*FIXME:*/E->getLocStart(), |
| 5366 | move_arg(PlacementArgs), |
| 5367 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 5368 | E->getTypeIdParens(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5369 | AllocType, |
| 5370 | /*FIXME:*/E->getLocStart(), |
| 5371 | /*FIXME:*/SourceRange(), |
| 5372 | move(ArraySize), |
| 5373 | /*FIXME:*/E->getLocStart(), |
| 5374 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5375 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5377 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5378 | template<typename Derived> |
| 5379 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5380 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5381 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5382 | if (Operand.isInvalid()) |
| 5383 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5385 | // Transform the delete operator, if known. |
| 5386 | FunctionDecl *OperatorDelete = 0; |
| 5387 | if (E->getOperatorDelete()) { |
| 5388 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5389 | getDerived().TransformDecl(E->getLocStart(), |
| 5390 | E->getOperatorDelete())); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5391 | if (!OperatorDelete) |
| 5392 | return SemaRef.ExprError(); |
| 5393 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5394 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5395 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5396 | Operand.get() == E->getArgument() && |
| 5397 | OperatorDelete == E->getOperatorDelete()) { |
| 5398 | // Mark any declarations we need as referenced. |
| 5399 | // FIXME: instantiation-specific. |
| 5400 | if (OperatorDelete) |
| 5401 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5404 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5405 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5406 | E->isGlobalDelete(), |
| 5407 | E->isArrayForm(), |
| 5408 | move(Operand)); |
| 5409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5411 | template<typename Derived> |
| 5412 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5413 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5414 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5415 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5416 | if (Base.isInvalid()) |
| 5417 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5419 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5420 | bool MayBePseudoDestructor = false; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5421 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5422 | E->getOperatorLoc(), |
| 5423 | E->isArrow()? tok::arrow : tok::period, |
| 5424 | ObjectTypePtr, |
| 5425 | MayBePseudoDestructor); |
| 5426 | if (Base.isInvalid()) |
| 5427 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5428 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5429 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5430 | NestedNameSpecifier *Qualifier |
| 5431 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5432 | E->getQualifierRange(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5433 | ObjectType); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5434 | if (E->getQualifier() && !Qualifier) |
| 5435 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5437 | PseudoDestructorTypeStorage Destroyed; |
| 5438 | if (E->getDestroyedTypeInfo()) { |
| 5439 | TypeSourceInfo *DestroyedTypeInfo |
| 5440 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5441 | if (!DestroyedTypeInfo) |
| 5442 | return SemaRef.ExprError(); |
| 5443 | Destroyed = DestroyedTypeInfo; |
| 5444 | } else if (ObjectType->isDependentType()) { |
| 5445 | // We aren't likely to be able to resolve the identifier down to a type |
| 5446 | // now anyway, so just retain the identifier. |
| 5447 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5448 | E->getDestroyedTypeLoc()); |
| 5449 | } else { |
| 5450 | // Look for a destructor known with the given name. |
| 5451 | CXXScopeSpec SS; |
| 5452 | if (Qualifier) { |
| 5453 | SS.setScopeRep(Qualifier); |
| 5454 | SS.setRange(E->getQualifierRange()); |
| 5455 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5457 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5458 | *E->getDestroyedTypeIdentifier(), |
| 5459 | E->getDestroyedTypeLoc(), |
| 5460 | /*Scope=*/0, |
| 5461 | SS, ObjectTypePtr, |
| 5462 | false); |
| 5463 | if (!T) |
| 5464 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5466 | Destroyed |
| 5467 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5468 | E->getDestroyedTypeLoc()); |
| 5469 | } |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5470 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5471 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5472 | if (E->getScopeTypeInfo()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5473 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5474 | ObjectType); |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5475 | if (!ScopeTypeInfo) |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5476 | return SemaRef.ExprError(); |
| 5477 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5478 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5479 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5480 | E->getOperatorLoc(), |
| 5481 | E->isArrow(), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5482 | Qualifier, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5483 | E->getQualifierRange(), |
| 5484 | ScopeTypeInfo, |
| 5485 | E->getColonColonLoc(), |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5486 | E->getTildeLoc(), |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5487 | Destroyed); |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5489 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5490 | template<typename Derived> |
| 5491 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5492 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5493 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5494 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5495 | |
| 5496 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5497 | Sema::LookupOrdinaryName); |
| 5498 | |
| 5499 | // Transform all the decls. |
| 5500 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5501 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5502 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5503 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5504 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5505 | if (!InstD) { |
| 5506 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5507 | // This can happen because of dependent hiding. |
| 5508 | if (isa<UsingShadowDecl>(*I)) |
| 5509 | continue; |
| 5510 | else |
| 5511 | return SemaRef.ExprError(); |
| 5512 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5513 | |
| 5514 | // Expand using declarations. |
| 5515 | if (isa<UsingDecl>(InstD)) { |
| 5516 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5517 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5518 | E = UD->shadow_end(); I != E; ++I) |
| 5519 | R.addDecl(*I); |
| 5520 | continue; |
| 5521 | } |
| 5522 | |
| 5523 | R.addDecl(InstD); |
| 5524 | } |
| 5525 | |
| 5526 | // Resolve a kind, but don't do any further analysis. If it's |
| 5527 | // ambiguous, the callee needs to deal with it. |
| 5528 | R.resolveKind(); |
| 5529 | |
| 5530 | // Rebuild the nested-name qualifier, if present. |
| 5531 | CXXScopeSpec SS; |
| 5532 | NestedNameSpecifier *Qualifier = 0; |
| 5533 | if (Old->getQualifier()) { |
| 5534 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5535 | Old->getQualifierRange()); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5536 | if (!Qualifier) |
| 5537 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5538 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5539 | SS.setScopeRep(Qualifier); |
| 5540 | SS.setRange(Old->getQualifierRange()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5543 | if (Old->getNamingClass()) { |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5544 | CXXRecordDecl *NamingClass |
| 5545 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5546 | Old->getNameLoc(), |
| 5547 | Old->getNamingClass())); |
| 5548 | if (!NamingClass) |
| 5549 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5550 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5551 | R.setNamingClass(NamingClass); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | // If we have no template arguments, it's a normal declaration name. |
| 5555 | if (!Old->hasExplicitTemplateArgs()) |
| 5556 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5557 | |
| 5558 | // If we have template arguments, rebuild them, then rebuild the |
| 5559 | // templateid expression. |
| 5560 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5561 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5562 | TemplateArgumentLoc Loc; |
| 5563 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5564 | return SemaRef.ExprError(); |
| 5565 | TransArgs.addArgument(Loc); |
| 5566 | } |
| 5567 | |
| 5568 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5569 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5570 | } |
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 | template<typename Derived> |
| 5573 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5574 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5575 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5576 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5577 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5578 | if (T.isNull()) |
| 5579 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5581 | if (!getDerived().AlwaysRebuild() && |
| 5582 | T == E->getQueriedType()) |
| 5583 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5585 | // FIXME: Bad location information |
| 5586 | SourceLocation FakeLParenLoc |
| 5587 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5588 | |
| 5589 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5590 | E->getLocStart(), |
| 5591 | /*FIXME:*/FakeLParenLoc, |
| 5592 | T, |
| 5593 | E->getLocEnd()); |
| 5594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5596 | template<typename Derived> |
| 5597 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5598 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5599 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5600 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5601 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5602 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5603 | if (!NNS) |
| 5604 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5605 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5606 | DeclarationNameInfo NameInfo |
| 5607 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 5608 | if (!NameInfo.getName()) |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5609 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5610 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5611 | if (!E->hasExplicitTemplateArgs()) { |
| 5612 | if (!getDerived().AlwaysRebuild() && |
| 5613 | NNS == E->getQualifier() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5614 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 5615 | // if name has not changed, DNLoc has not changed either. |
| 5616 | NameInfo.getName() == E->getDeclName()) |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5617 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5618 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5619 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5620 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5621 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5622 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5623 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5624 | |
| 5625 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5626 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5627 | TemplateArgumentLoc Loc; |
| 5628 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5629 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5630 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5631 | } |
| 5632 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5633 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5634 | E->getQualifierRange(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5635 | NameInfo, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5636 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | template<typename Derived> |
| 5640 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5641 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5642 | // CXXConstructExprs are always implicit, so when we have a |
| 5643 | // 1-argument construction we just transform that argument. |
| 5644 | if (E->getNumArgs() == 1 || |
| 5645 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5646 | return getDerived().TransformExpr(E->getArg(0)); |
| 5647 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5648 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5649 | |
| 5650 | QualType T = getDerived().TransformType(E->getType()); |
| 5651 | if (T.isNull()) |
| 5652 | return SemaRef.ExprError(); |
| 5653 | |
| 5654 | CXXConstructorDecl *Constructor |
| 5655 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5656 | getDerived().TransformDecl(E->getLocStart(), |
| 5657 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5658 | if (!Constructor) |
| 5659 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5660 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5661 | bool ArgumentChanged = false; |
| 5662 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5663 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5664 | ArgEnd = E->arg_end(); |
| 5665 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5666 | if (getDerived().DropCallArgument(*Arg)) { |
| 5667 | ArgumentChanged = true; |
| 5668 | break; |
| 5669 | } |
| 5670 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5671 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5672 | if (TransArg.isInvalid()) |
| 5673 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5675 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5676 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5677 | } |
| 5678 | |
| 5679 | if (!getDerived().AlwaysRebuild() && |
| 5680 | T == E->getType() && |
| 5681 | Constructor == E->getConstructor() && |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5682 | !ArgumentChanged) { |
Douglas Gregor | 1af7451 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5683 | // Mark the constructor as referenced. |
| 5684 | // FIXME: Instantiation-specific |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5685 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | c845aad | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5687 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5688 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5689 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5690 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5691 | move_arg(Args)); |
| 5692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | /// \brief Transform a C++ temporary-binding expression. |
| 5695 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5696 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5697 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5698 | template<typename Derived> |
| 5699 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5700 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5701 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5702 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5703 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5704 | /// \brief Transform a C++ reference-binding expression. |
| 5705 | /// |
| 5706 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5707 | /// transform the subexpression and return that. |
| 5708 | template<typename Derived> |
| 5709 | Sema::OwningExprResult |
| 5710 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5711 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5712 | } |
| 5713 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5714 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5715 | /// be destroyed after the expression is evaluated. |
| 5716 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5717 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5718 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5719 | template<typename Derived> |
| 5720 | Sema::OwningExprResult |
| 5721 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5722 | CXXExprWithTemporaries *E) { |
| 5723 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5726 | template<typename Derived> |
| 5727 | Sema::OwningExprResult |
| 5728 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5729 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5731 | QualType T = getDerived().TransformType(E->getType()); |
| 5732 | if (T.isNull()) |
| 5733 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5734 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5735 | CXXConstructorDecl *Constructor |
| 5736 | = cast_or_null<CXXConstructorDecl>( |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5737 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5738 | E->getConstructor())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5739 | if (!Constructor) |
| 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 | bool ArgumentChanged = false; |
| 5743 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5744 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5745 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5746 | ArgEnd = E->arg_end(); |
| 5747 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5748 | if (getDerived().DropCallArgument(*Arg)) { |
| 5749 | ArgumentChanged = true; |
| 5750 | break; |
| 5751 | } |
| 5752 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5753 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5754 | if (TransArg.isInvalid()) |
| 5755 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5756 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5757 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5758 | Args.push_back((Expr *)TransArg.release()); |
| 5759 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5760 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5761 | if (!getDerived().AlwaysRebuild() && |
| 5762 | T == E->getType() && |
| 5763 | Constructor == E->getConstructor() && |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5764 | !ArgumentChanged) { |
| 5765 | // FIXME: Instantiation-specific |
| 5766 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | a3ce8ae | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5767 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 91be6f5 | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 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 | // FIXME: Bogus location information |
| 5771 | SourceLocation CommaLoc; |
| 5772 | if (Args.size() > 1) { |
| 5773 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5774 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5775 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5776 | } |
| 5777 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5778 | T, |
| 5779 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5780 | move_arg(Args), |
| 5781 | &CommaLoc, |
| 5782 | E->getLocEnd()); |
| 5783 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5784 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5785 | template<typename Derived> |
| 5786 | Sema::OwningExprResult |
| 5787 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5788 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5789 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5790 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5791 | if (T.isNull()) |
| 5792 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5793 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5794 | bool ArgumentChanged = false; |
| 5795 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5796 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5797 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5798 | ArgEnd = E->arg_end(); |
| 5799 | Arg != ArgEnd; ++Arg) { |
| 5800 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5801 | if (TransArg.isInvalid()) |
| 5802 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5804 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5805 | FakeCommaLocs.push_back( |
| 5806 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5807 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5808 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5809 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5810 | if (!getDerived().AlwaysRebuild() && |
| 5811 | T == E->getTypeAsWritten() && |
| 5812 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | return SemaRef.Owned(E->Retain()); |
| 5814 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5815 | // FIXME: we're faking the locations of the commas |
| 5816 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5817 | T, |
| 5818 | E->getLParenLoc(), |
| 5819 | move_arg(Args), |
| 5820 | FakeCommaLocs.data(), |
| 5821 | E->getRParenLoc()); |
| 5822 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5823 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5824 | template<typename Derived> |
| 5825 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5826 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5827 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5828 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5829 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5830 | Expr *OldBase; |
| 5831 | QualType BaseType; |
| 5832 | QualType ObjectType; |
| 5833 | if (!E->isImplicitAccess()) { |
| 5834 | OldBase = E->getBase(); |
| 5835 | Base = getDerived().TransformExpr(OldBase); |
| 5836 | if (Base.isInvalid()) |
| 5837 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5838 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5839 | // Start the member reference and compute the object's type. |
| 5840 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5841 | bool MayBePseudoDestructor = false; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5842 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5843 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5844 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5845 | ObjectTy, |
| 5846 | MayBePseudoDestructor); |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5847 | if (Base.isInvalid()) |
| 5848 | return SemaRef.ExprError(); |
| 5849 | |
| 5850 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5851 | BaseType = ((Expr*) Base.get())->getType(); |
| 5852 | } else { |
| 5853 | OldBase = 0; |
| 5854 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5855 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5856 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5857 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5858 | // Transform the first part of the nested-name-specifier that qualifies |
| 5859 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5860 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5861 | = getDerived().TransformFirstQualifierInScope( |
| 5862 | E->getFirstQualifierFoundInScope(), |
| 5863 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5864 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5865 | NestedNameSpecifier *Qualifier = 0; |
| 5866 | if (E->getQualifier()) { |
| 5867 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5868 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5869 | ObjectType, |
| 5870 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5871 | if (!Qualifier) |
| 5872 | return SemaRef.ExprError(); |
| 5873 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5874 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5875 | DeclarationNameInfo NameInfo |
| 5876 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(), |
| 5877 | ObjectType); |
| 5878 | if (!NameInfo.getName()) |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5879 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5880 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5881 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5882 | // This is a reference to a member without an explicitly-specified |
| 5883 | // template argument list. Optimize for this common case. |
| 5884 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5885 | Base.get() == OldBase && |
| 5886 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5887 | Qualifier == E->getQualifier() && |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5888 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5889 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5890 | return SemaRef.Owned(E->Retain()); |
| 5891 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5892 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5893 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5894 | E->isArrow(), |
| 5895 | E->getOperatorLoc(), |
| 5896 | Qualifier, |
| 5897 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5898 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5899 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5900 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5901 | } |
| 5902 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5903 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5904 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5905 | TemplateArgumentLoc Loc; |
| 5906 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5907 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5908 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5910 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5911 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5912 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5913 | E->isArrow(), |
| 5914 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5915 | Qualifier, |
| 5916 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5917 | FirstQualifierInScope, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5918 | NameInfo, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5919 | &TransArgs); |
| 5920 | } |
| 5921 | |
| 5922 | template<typename Derived> |
| 5923 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5924 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5925 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5926 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5927 | QualType BaseType; |
| 5928 | if (!Old->isImplicitAccess()) { |
| 5929 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5930 | if (Base.isInvalid()) |
| 5931 | return SemaRef.ExprError(); |
| 5932 | BaseType = ((Expr*) Base.get())->getType(); |
| 5933 | } else { |
| 5934 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5935 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5936 | |
| 5937 | NestedNameSpecifier *Qualifier = 0; |
| 5938 | if (Old->getQualifier()) { |
| 5939 | Qualifier |
| 5940 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5941 | Old->getQualifierRange()); |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5942 | if (Qualifier == 0) |
| 5943 | return SemaRef.ExprError(); |
| 5944 | } |
| 5945 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5946 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5947 | Sema::LookupOrdinaryName); |
| 5948 | |
| 5949 | // Transform all the decls. |
| 5950 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5951 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | 7c1e98f | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5952 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5953 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5954 | *I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5955 | if (!InstD) { |
| 5956 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5957 | // This can happen because of dependent hiding. |
| 5958 | if (isa<UsingShadowDecl>(*I)) |
| 5959 | continue; |
| 5960 | else |
| 5961 | return SemaRef.ExprError(); |
| 5962 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5963 | |
| 5964 | // Expand using declarations. |
| 5965 | if (isa<UsingDecl>(InstD)) { |
| 5966 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5967 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5968 | E = UD->shadow_end(); I != E; ++I) |
| 5969 | R.addDecl(*I); |
| 5970 | continue; |
| 5971 | } |
| 5972 | |
| 5973 | R.addDecl(InstD); |
| 5974 | } |
| 5975 | |
| 5976 | R.resolveKind(); |
| 5977 | |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5978 | // Determine the naming class. |
Chandler Carruth | 042d6f9 | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 5979 | if (Old->getNamingClass()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5980 | CXXRecordDecl *NamingClass |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5981 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5982 | Old->getMemberLoc(), |
| 5983 | Old->getNamingClass())); |
| 5984 | if (!NamingClass) |
| 5985 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5986 | |
Douglas Gregor | 66c4515 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5987 | R.setNamingClass(NamingClass); |
Douglas Gregor | c96be1e | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5988 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5989 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5990 | TemplateArgumentListInfo TransArgs; |
| 5991 | if (Old->hasExplicitTemplateArgs()) { |
| 5992 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5993 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5994 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5995 | TemplateArgumentLoc Loc; |
| 5996 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5997 | Loc)) |
| 5998 | return SemaRef.ExprError(); |
| 5999 | TransArgs.addArgument(Loc); |
| 6000 | } |
| 6001 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6002 | |
| 6003 | // FIXME: to do this check properly, we will need to preserve the |
| 6004 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6005 | // base (and therefore couldn't do the check) and a |
| 6006 | // nested-name-qualifier (and therefore could do the lookup). |
| 6007 | NamedDecl *FirstQualifierInScope = 0; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6008 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6009 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6010 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6011 | Old->getOperatorLoc(), |
| 6012 | Old->isArrow(), |
| 6013 | Qualifier, |
| 6014 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6015 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6016 | R, |
| 6017 | (Old->hasExplicitTemplateArgs() |
| 6018 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | template<typename Derived> |
| 6022 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6023 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
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 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6027 | template<typename Derived> |
| 6028 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6029 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6030 | TypeSourceInfo *EncodedTypeInfo |
| 6031 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 6032 | if (!EncodedTypeInfo) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6033 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6034 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6035 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6036 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6037 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6038 | |
| 6039 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | 81d3466 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6040 | EncodedTypeInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6041 | E->getRParenLoc()); |
| 6042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6043 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6044 | template<typename Derived> |
| 6045 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6046 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6047 | // Transform arguments. |
| 6048 | bool ArgChanged = false; |
| 6049 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 6050 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 6051 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 6052 | if (Arg.isInvalid()) |
| 6053 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6054 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6055 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 6056 | Args.push_back(Arg.takeAs<Expr>()); |
| 6057 | } |
| 6058 | |
| 6059 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 6060 | // Class message: transform the receiver type. |
| 6061 | TypeSourceInfo *ReceiverTypeInfo |
| 6062 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 6063 | if (!ReceiverTypeInfo) |
| 6064 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6065 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6066 | // If nothing changed, just retain the existing message send. |
| 6067 | if (!getDerived().AlwaysRebuild() && |
| 6068 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 6069 | return SemaRef.Owned(E->Retain()); |
| 6070 | |
| 6071 | // Build a new class message send. |
| 6072 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 6073 | E->getSelector(), |
| 6074 | E->getMethodDecl(), |
| 6075 | E->getLeftLoc(), |
| 6076 | move_arg(Args), |
| 6077 | E->getRightLoc()); |
| 6078 | } |
| 6079 | |
| 6080 | // Instance message: transform the receiver |
| 6081 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 6082 | "Only class and instance messages may be instantiated"); |
| 6083 | OwningExprResult Receiver |
| 6084 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 6085 | if (Receiver.isInvalid()) |
| 6086 | return SemaRef.ExprError(); |
| 6087 | |
| 6088 | // If nothing changed, just retain the existing message send. |
| 6089 | if (!getDerived().AlwaysRebuild() && |
| 6090 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 6091 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6092 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6093 | // Build a new instance message send. |
| 6094 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 6095 | E->getSelector(), |
| 6096 | E->getMethodDecl(), |
| 6097 | E->getLeftLoc(), |
| 6098 | move_arg(Args), |
| 6099 | E->getRightLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6102 | template<typename Derived> |
| 6103 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6104 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6105 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6106 | } |
| 6107 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6108 | template<typename Derived> |
| 6109 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6110 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6111 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6112 | } |
| 6113 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6114 | template<typename Derived> |
| 6115 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6116 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6117 | // Transform the base expression. |
| 6118 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6119 | if (Base.isInvalid()) |
| 6120 | return SemaRef.ExprError(); |
| 6121 | |
| 6122 | // We don't need to transform the ivar; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6123 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6124 | // If nothing changed, just retain the existing expression. |
| 6125 | if (!getDerived().AlwaysRebuild() && |
| 6126 | Base.get() == E->getBase()) |
| 6127 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6128 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6129 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6130 | E->getLocation(), |
| 6131 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6132 | } |
| 6133 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6134 | template<typename Derived> |
| 6135 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6136 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6137 | // Transform the base expression. |
| 6138 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6139 | if (Base.isInvalid()) |
| 6140 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6141 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6142 | // We don't need to transform the property; it will never change. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6144 | // If nothing changed, just retain the existing expression. |
| 6145 | if (!getDerived().AlwaysRebuild() && |
| 6146 | Base.get() == E->getBase()) |
| 6147 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6148 | |
Douglas Gregor | e330354 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6149 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6150 | E->getLocation()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6151 | } |
| 6152 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6153 | template<typename Derived> |
| 6154 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6155 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6156 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6157 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6158 | // dependent parts. Just retain the existing declaration. |
| 6159 | if (E->getInterfaceDecl()) |
| 6160 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6161 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6162 | // Transform the base expression. |
| 6163 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6164 | if (Base.isInvalid()) |
| 6165 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6166 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6167 | // 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] | 6168 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6169 | // If nothing changed, just retain the existing expression. |
| 6170 | if (!getDerived().AlwaysRebuild() && |
| 6171 | Base.get() == E->getBase()) |
| 6172 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6173 | |
Douglas Gregor | 9cbfdd2 | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6174 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6175 | E->getGetterMethod(), |
| 6176 | E->getType(), |
| 6177 | E->getSetterMethod(), |
| 6178 | E->getLocation(), |
| 6179 | move(Base)); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6181 | } |
| 6182 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6183 | template<typename Derived> |
| 6184 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6185 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | ef57c61 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6186 | // Can never occur in a dependent context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6187 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6188 | } |
| 6189 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6190 | template<typename Derived> |
| 6191 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6192 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6193 | // Transform the base expression. |
| 6194 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6195 | if (Base.isInvalid()) |
| 6196 | return SemaRef.ExprError(); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6197 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6198 | // If nothing changed, just retain the existing expression. |
| 6199 | if (!getDerived().AlwaysRebuild() && |
| 6200 | Base.get() == E->getBase()) |
| 6201 | return SemaRef.Owned(E->Retain()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6202 | |
Douglas Gregor | f9b9eab | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6203 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6204 | E->isArrow()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6207 | template<typename Derived> |
| 6208 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6209 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6210 | bool ArgumentChanged = false; |
| 6211 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6212 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6213 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6214 | if (SubExpr.isInvalid()) |
| 6215 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6216 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6217 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6218 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6219 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6220 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6221 | if (!getDerived().AlwaysRebuild() && |
| 6222 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6223 | return SemaRef.Owned(E->Retain()); |
| 6224 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6225 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6226 | move_arg(SubExprs), |
| 6227 | E->getRParenLoc()); |
| 6228 | } |
| 6229 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6230 | template<typename Derived> |
| 6231 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6232 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6233 | SourceLocation CaretLoc(E->getExprLoc()); |
| 6234 | |
| 6235 | SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0); |
| 6236 | BlockScopeInfo *CurBlock = SemaRef.getCurBlock(); |
| 6237 | CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic()); |
| 6238 | llvm::SmallVector<ParmVarDecl*, 4> Params; |
| 6239 | llvm::SmallVector<QualType, 4> ParamTypes; |
| 6240 | |
| 6241 | // Parameter substitution. |
| 6242 | const BlockDecl *BD = E->getBlockDecl(); |
| 6243 | for (BlockDecl::param_const_iterator P = BD->param_begin(), |
| 6244 | EN = BD->param_end(); P != EN; ++P) { |
| 6245 | ParmVarDecl *OldParm = (*P); |
| 6246 | ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 6247 | QualType NewType = NewParm->getType(); |
| 6248 | Params.push_back(NewParm); |
| 6249 | ParamTypes.push_back(NewParm->getType()); |
| 6250 | } |
| 6251 | |
| 6252 | const FunctionType *BExprFunctionType = E->getFunctionType(); |
| 6253 | QualType BExprResultType = BExprFunctionType->getResultType(); |
| 6254 | if (!BExprResultType.isNull()) { |
| 6255 | if (!BExprResultType->isDependentType()) |
| 6256 | CurBlock->ReturnType = BExprResultType; |
| 6257 | else if (BExprResultType != SemaRef.Context.DependentTy) |
| 6258 | CurBlock->ReturnType = getDerived().TransformType(BExprResultType); |
| 6259 | } |
| 6260 | |
| 6261 | // Transform the body |
| 6262 | OwningStmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 6263 | if (Body.isInvalid()) |
| 6264 | return SemaRef.ExprError(); |
| 6265 | // Set the parameters on the block decl. |
| 6266 | if (!Params.empty()) |
| 6267 | CurBlock->TheDecl->setParams(Params.data(), Params.size()); |
| 6268 | |
| 6269 | QualType FunctionType = getDerived().RebuildFunctionProtoType( |
| 6270 | CurBlock->ReturnType, |
| 6271 | ParamTypes.data(), |
| 6272 | ParamTypes.size(), |
| 6273 | BD->isVariadic(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6274 | 0, |
| 6275 | BExprFunctionType->getExtInfo()); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6276 | |
| 6277 | CurBlock->FunctionType = FunctionType; |
| 6278 | return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6279 | } |
| 6280 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | template<typename Derived> |
| 6282 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6283 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6284 | NestedNameSpecifier *Qualifier = 0; |
| 6285 | |
| 6286 | ValueDecl *ND |
| 6287 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6288 | E->getDecl())); |
| 6289 | if (!ND) |
| 6290 | return SemaRef.ExprError(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6291 | |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6292 | if (!getDerived().AlwaysRebuild() && |
| 6293 | ND == E->getDecl()) { |
| 6294 | // Mark it referenced in the new context regardless. |
| 6295 | // FIXME: this is a bit instantiation-specific. |
| 6296 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 6297 | |
| 6298 | return SemaRef.Owned(E->Retain()); |
| 6299 | } |
| 6300 | |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6301 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Fariborz Jahanian | a729da2 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6302 | return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(), |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6303 | ND, NameInfo, 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6305 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6306 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6307 | // Type reconstruction |
| 6308 | //===----------------------------------------------------------------------===// |
| 6309 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6310 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6311 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6312 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6313 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6314 | getDerived().getBaseEntity()); |
| 6315 | } |
| 6316 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6317 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6318 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6319 | SourceLocation Star) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6320 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6321 | getDerived().getBaseEntity()); |
| 6322 | } |
| 6323 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6324 | template<typename Derived> |
| 6325 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6326 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6327 | bool WrittenAsLValue, |
| 6328 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6329 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6330 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6334 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6335 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6336 | QualType ClassType, |
| 6337 | SourceLocation Sigil) { |
John McCall | 2865474 | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6338 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6339 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6343 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6344 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6345 | ArrayType::ArraySizeModifier SizeMod, |
| 6346 | const llvm::APInt *Size, |
| 6347 | Expr *SizeExpr, |
| 6348 | unsigned IndexTypeQuals, |
| 6349 | SourceRange BracketsRange) { |
| 6350 | if (SizeExpr || !Size) |
| 6351 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6352 | IndexTypeQuals, BracketsRange, |
| 6353 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6354 | |
| 6355 | QualType Types[] = { |
| 6356 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6357 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6358 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6359 | }; |
| 6360 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6361 | QualType SizeType; |
| 6362 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6363 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6364 | SizeType = Types[I]; |
| 6365 | break; |
| 6366 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6367 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6368 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6369 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6370 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6371 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6372 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6373 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6374 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6375 | QualType |
| 6376 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6377 | ArrayType::ArraySizeModifier SizeMod, |
| 6378 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6379 | unsigned IndexTypeQuals, |
| 6380 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6381 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6382 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6386 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6387 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6388 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6389 | unsigned IndexTypeQuals, |
| 6390 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6391 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6392 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6393 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6394 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6395 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6396 | QualType |
| 6397 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6398 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6399 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6400 | unsigned IndexTypeQuals, |
| 6401 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6402 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6403 | SizeExpr.takeAs<Expr>(), |
| 6404 | IndexTypeQuals, BracketsRange); |
| 6405 | } |
| 6406 | |
| 6407 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6408 | QualType |
| 6409 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6411 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6412 | unsigned IndexTypeQuals, |
| 6413 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6414 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6415 | SizeExpr.takeAs<Expr>(), |
| 6416 | IndexTypeQuals, BracketsRange); |
| 6417 | } |
| 6418 | |
| 6419 | template<typename Derived> |
| 6420 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6421 | unsigned NumElements, |
| 6422 | VectorType::AltiVecSpecific AltiVecSpec) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6423 | // FIXME: semantic checking! |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6424 | return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6425 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6426 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6427 | template<typename Derived> |
| 6428 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6429 | unsigned NumElements, |
| 6430 | SourceLocation AttributeLoc) { |
| 6431 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6432 | NumElements, true); |
| 6433 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6434 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6435 | AttributeLoc); |
| 6436 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6437 | AttributeLoc); |
| 6438 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6439 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6440 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6441 | QualType |
| 6442 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6443 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6444 | SourceLocation AttributeLoc) { |
| 6445 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6446 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6447 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6448 | template<typename Derived> |
| 6449 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6450 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6451 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6452 | bool Variadic, |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6453 | unsigned Quals, |
| 6454 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6455 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6456 | Quals, |
| 6457 | getDerived().getBaseLocation(), |
Eli Friedman | fa86954 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6458 | getDerived().getBaseEntity(), |
| 6459 | Info); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6462 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6463 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6464 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6465 | } |
| 6466 | |
| 6467 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6468 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6469 | assert(D && "no decl found"); |
| 6470 | if (D->isInvalidDecl()) return QualType(); |
| 6471 | |
Douglas Gregor | 92e986e | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6472 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6473 | TypeDecl *Ty; |
| 6474 | if (isa<UsingDecl>(D)) { |
| 6475 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6476 | assert(Using->isTypeName() && |
| 6477 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6478 | |
| 6479 | // A valid resolved using typename decl points to exactly one type decl. |
| 6480 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6481 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6482 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6483 | } else { |
| 6484 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6485 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6486 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6487 | } |
| 6488 | |
| 6489 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6490 | } |
| 6491 | |
| 6492 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6493 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6494 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6495 | } |
| 6496 | |
| 6497 | template<typename Derived> |
| 6498 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6499 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6500 | } |
| 6501 | |
| 6502 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6503 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6504 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6505 | } |
| 6506 | |
| 6507 | template<typename Derived> |
| 6508 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6509 | TemplateName Template, |
| 6510 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6511 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6512 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6513 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6515 | template<typename Derived> |
| 6516 | NestedNameSpecifier * |
| 6517 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6518 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6519 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6520 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6521 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6522 | CXXScopeSpec SS; |
| 6523 | // FIXME: The source location information is all wrong. |
| 6524 | SS.setRange(Range); |
| 6525 | SS.setScopeRep(Prefix); |
| 6526 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6527 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6528 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6529 | ObjectType, |
| 6530 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6531 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
| 6534 | template<typename Derived> |
| 6535 | NestedNameSpecifier * |
| 6536 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6537 | SourceRange Range, |
| 6538 | NamespaceDecl *NS) { |
| 6539 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6540 | } |
| 6541 | |
| 6542 | template<typename Derived> |
| 6543 | NestedNameSpecifier * |
| 6544 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6545 | SourceRange Range, |
| 6546 | bool TemplateKW, |
Douglas Gregor | edc9050 | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6547 | QualType T) { |
| 6548 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6549 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6550 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6551 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6552 | T.getTypePtr()); |
| 6553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6554 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6555 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6556 | return 0; |
| 6557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6558 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6559 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6560 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6561 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6562 | bool TemplateKW, |
| 6563 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6564 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6565 | Template); |
| 6566 | } |
| 6567 | |
| 6568 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6569 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6570 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6571 | const IdentifierInfo &II, |
| 6572 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6573 | CXXScopeSpec SS; |
| 6574 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6575 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6576 | UnqualifiedId Name; |
| 6577 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6578 | Sema::TemplateTy Template; |
| 6579 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 6580 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6581 | SS, |
| 6582 | Name, |
| 6583 | ObjectType.getAsOpaquePtr(), |
| 6584 | /*EnteringContext=*/false, |
| 6585 | Template); |
| 6586 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6587 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6588 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6589 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6590 | TemplateName |
| 6591 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6592 | OverloadedOperatorKind Operator, |
| 6593 | QualType ObjectType) { |
| 6594 | CXXScopeSpec SS; |
| 6595 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6596 | SS.setScopeRep(Qualifier); |
| 6597 | UnqualifiedId Name; |
| 6598 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6599 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6600 | Operator, SymbolLocations); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6601 | Sema::TemplateTy Template; |
| 6602 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6603 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6604 | SS, |
| 6605 | Name, |
| 6606 | ObjectType.getAsOpaquePtr(), |
| 6607 | /*EnteringContext=*/false, |
| 6608 | Template); |
| 6609 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6610 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6611 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6612 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6613 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6614 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6615 | SourceLocation OpLoc, |
| 6616 | ExprArg Callee, |
| 6617 | ExprArg First, |
| 6618 | ExprArg Second) { |
| 6619 | Expr *FirstExpr = (Expr *)First.get(); |
| 6620 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6621 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6622 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
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 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6625 | if (Op == OO_Subscript) { |
| 6626 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6627 | !SecondExpr->getType()->isOverloadableType()) |
| 6628 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6629 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6630 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6631 | } else if (Op == OO_Arrow) { |
| 6632 | // -> is never a builtin operation. |
| 6633 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6634 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6635 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6636 | // The argument is not of overloadable type, so try to create a |
| 6637 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6638 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6639 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6640 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6641 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6642 | } |
| 6643 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6644 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6645 | !SecondExpr->getType()->isOverloadableType()) { |
| 6646 | // Neither of the arguments is an overloadable type, so try to |
| 6647 | // create a built-in binary operation. |
| 6648 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6649 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6650 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6651 | if (Result.isInvalid()) |
| 6652 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | First.release(); |
| 6655 | Second.release(); |
| 6656 | return move(Result); |
| 6657 | } |
| 6658 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6659 | |
| 6660 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6661 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6662 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6663 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6664 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6665 | assert(ULE->requiresADL()); |
| 6666 | |
| 6667 | // FIXME: Do we have to check |
| 6668 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6669 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6670 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6671 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6672 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6673 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6674 | // Add any functions found via argument-dependent lookup. |
| 6675 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6676 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6677 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6678 | // Create the overloaded operator invocation for unary operators. |
| 6679 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6680 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6681 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6682 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6684 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6685 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6686 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6687 | OpLoc, |
| 6688 | move(First), |
| 6689 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6690 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6691 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6692 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6693 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6694 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6695 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6696 | if (Result.isInvalid()) |
| 6697 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6698 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6699 | First.release(); |
| 6700 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6701 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6702 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6703 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6704 | template<typename Derived> |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6705 | Sema::OwningExprResult |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6706 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6707 | SourceLocation OperatorLoc, |
| 6708 | bool isArrow, |
| 6709 | NestedNameSpecifier *Qualifier, |
| 6710 | SourceRange QualifierRange, |
| 6711 | TypeSourceInfo *ScopeType, |
| 6712 | SourceLocation CCLoc, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6713 | SourceLocation TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6714 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6715 | CXXScopeSpec SS; |
| 6716 | if (Qualifier) { |
| 6717 | SS.setRange(QualifierRange); |
| 6718 | SS.setScopeRep(Qualifier); |
| 6719 | } |
| 6720 | |
| 6721 | Expr *BaseE = (Expr *)Base.get(); |
| 6722 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6723 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6724 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6725 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | bf2ca2f | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6726 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6727 | ->template getAs<RecordType>())){ |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6728 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6729 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6730 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | fce46ee | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6731 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6732 | Destroyed, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6733 | /*FIXME?*/true); |
| 6734 | } |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6735 | |
Douglas Gregor | a2e7dd2 | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6736 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6737 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6738 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 6739 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 6740 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 6741 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6742 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6743 | |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6744 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6745 | OperatorLoc, isArrow, |
| 6746 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6747 | NameInfo, |
Douglas Gregor | 26d4ac9 | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6748 | /*TemplateArgs*/ 0); |
| 6749 | } |
| 6750 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6751 | } // end namespace clang |
| 6752 | |
| 6753 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |