John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "Sema.h" |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 23 | #include "clang/AST/Stmt.h" |
| 24 | #include "clang/AST/StmtCXX.h" |
| 25 | #include "clang/AST/StmtObjC.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 27 | #include "clang/Parse/Ownership.h" |
| 28 | #include "clang/Parse/Designator.h" |
| 29 | #include "clang/Lex/Preprocessor.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | /// \brief A semantic tree transformation that allows one to transform one |
| 36 | /// abstract syntax tree into another. |
| 37 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 39 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 40 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 41 | /// instantiation is implemented as a tree transformation where the |
| 42 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 43 | /// template arguments for their corresponding template parameters; a similar |
| 44 | /// transformation is performed for non-type template parameters and |
| 45 | /// template template parameters. |
| 46 | /// |
| 47 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// override any of the transformation or rebuild operators by providing an |
| 50 | /// operation with the same signature as the default implementation. The |
| 51 | /// overridding function should not be virtual. |
| 52 | /// |
| 53 | /// Semantic tree transformations are split into two stages, either of which |
| 54 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 55 | /// or the parts of an AST node using the various transformation functions, |
| 56 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 57 | /// node of the appropriate kind from the pieces. The default transformation |
| 58 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 59 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 60 | /// were changed by the transformation, invokes the rebuild operation to create |
| 61 | /// a new AST node. |
| 62 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 65 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 66 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 67 | /// new implementations. |
| 68 | /// |
| 69 | /// For more fine-grained transformations, subclasses can replace any of the |
| 70 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 75 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 76 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 77 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 78 | /// be able to use more efficient rebuild steps. |
| 79 | /// |
| 80 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 83 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 84 | /// default locations and entity names used for type-checking |
| 85 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 92 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 93 | typedef Sema::OwningExprResult OwningExprResult; |
| 94 | typedef Sema::StmtArg StmtArg; |
| 95 | typedef Sema::ExprArg ExprArg; |
| 96 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 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 | } |
| 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. |
| 194 | QualType TransformType(QualType T); |
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. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 205 | |
| 206 | /// \brief Transform the given type-with-location into a new |
| 207 | /// type, collecting location information in the given builder |
| 208 | /// as necessary. |
| 209 | /// |
| 210 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 212 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 213 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 214 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 215 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 216 | /// statement or the TransformExpr() function to transform an expression. |
| 217 | /// Subclasses may override this function to transform statements using some |
| 218 | /// other mechanism. |
| 219 | /// |
| 220 | /// \returns the transformed statement. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 221 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 222 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 223 | /// \brief Transform the given expression. |
| 224 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 225 | /// By default, this routine transforms an expression by delegating to the |
| 226 | /// appropriate TransformXXXExpr function to build a new expression. |
| 227 | /// Subclasses may override this function to transform expressions using some |
| 228 | /// other mechanism. |
| 229 | /// |
| 230 | /// \returns the transformed expression. |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 231 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 233 | /// \brief Transform the given declaration, which is referenced from a type |
| 234 | /// or expression. |
| 235 | /// |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 236 | /// By default, acts as the identity function on declarations. Subclasses |
| 237 | /// may override this function to provide alternate behavior. |
| 238 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 239 | |
| 240 | /// \brief Transform the definition of the given declaration. |
| 241 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 243 | /// Subclasses may override this function to provide alternate behavior. |
| 244 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 246 | /// \brief Transform the given declaration, which was the first part of a |
| 247 | /// nested-name-specifier in a member access expression. |
| 248 | /// |
| 249 | /// This specific declaration transformation only applies to the first |
| 250 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 251 | /// the \c T in \c x->T::member |
| 252 | /// |
| 253 | /// By default, invokes TransformDecl() to transform the declaration. |
| 254 | /// Subclasses may override this function to provide alternate behavior. |
| 255 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 256 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 257 | } |
| 258 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 259 | /// \brief Transform the given nested-name-specifier. |
| 260 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 262 | /// nested-name-specifier. Subclasses may override this function to provide |
| 263 | /// alternate behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 264 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 265 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 266 | QualType ObjectType = QualType(), |
| 267 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 269 | /// \brief Transform the given declaration name. |
| 270 | /// |
| 271 | /// By default, transforms the types of conversion function, constructor, |
| 272 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 273 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 274 | /// override this function to provide alternate behavior. |
| 275 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 276 | SourceLocation Loc, |
| 277 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 281 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 284 | TemplateName TransformTemplateName(TemplateName Name, |
| 285 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 287 | /// \brief Transform the given template argument. |
| 288 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | /// By default, this operation transforms the type, expression, or |
| 290 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 291 | /// new template argument from the transformed result. Subclasses may |
| 292 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 293 | /// |
| 294 | /// Returns true if there was an error. |
| 295 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 296 | TemplateArgumentLoc &Output); |
| 297 | |
| 298 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 299 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 300 | TemplateArgumentLoc &ArgLoc); |
| 301 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 302 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 303 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 304 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 305 | getDerived().getBaseLocation()); |
| 306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 308 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 309 | #define TYPELOC(CLASS, PARENT) \ |
| 310 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 311 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 312 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 313 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 314 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 315 | QualType |
| 316 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 317 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 318 | |
| 319 | QualType |
| 320 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 321 | TemplateSpecializationTypeLoc TL, |
| 322 | QualType ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | #define STMT(Node, Parent) \ |
| 327 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 328 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 329 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define ABSTRACT_EXPR(Node, Parent) |
| 331 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 333 | /// \brief Build a new pointer type given its pointee type. |
| 334 | /// |
| 335 | /// By default, performs semantic analysis when building the pointer type. |
| 336 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 337 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | |
| 339 | /// \brief Build a new block pointer type given its pointee type. |
| 340 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 342 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 343 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// By default, performs semantic analysis when building the |
| 348 | /// reference type. Subclasses may override this routine to provide |
| 349 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 351 | /// \param LValue whether the type was written with an lvalue sigil |
| 352 | /// or an rvalue sigil. |
| 353 | QualType RebuildReferenceType(QualType ReferentType, |
| 354 | bool LValue, |
| 355 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 357 | /// \brief Build a new member pointer type given the pointee type and the |
| 358 | /// class type it refers into. |
| 359 | /// |
| 360 | /// By default, performs semantic analysis when building the member pointer |
| 361 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 363 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 365 | /// \brief Build a new Objective C object pointer type. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 366 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 367 | SourceLocation Sigil); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 369 | /// \brief Build a new array type given the element type, size |
| 370 | /// modifier, size of the array (if known), size expression, and index type |
| 371 | /// qualifiers. |
| 372 | /// |
| 373 | /// By default, performs semantic analysis when building the array type. |
| 374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | QualType RebuildArrayType(QualType ElementType, |
| 377 | ArrayType::ArraySizeModifier SizeMod, |
| 378 | const llvm::APInt *Size, |
| 379 | Expr *SizeExpr, |
| 380 | unsigned IndexTypeQuals, |
| 381 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | /// \brief Build a new constant array type given the element type, size |
| 384 | /// modifier, (known) size of the array, and index type 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 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 391 | unsigned IndexTypeQuals, |
| 392 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | /// \brief Build a new incomplete array type given the element type, size |
| 395 | /// modifier, and index type qualifiers. |
| 396 | /// |
| 397 | /// By default, performs semantic analysis when building the array type. |
| 398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 400 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 401 | unsigned IndexTypeQuals, |
| 402 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 403 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// size modifier, size expression, and index type qualifiers. |
| 406 | /// |
| 407 | /// By default, performs semantic analysis when building the array type. |
| 408 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | unsigned IndexTypeQuals, |
| 413 | SourceRange BracketsRange); |
| 414 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | /// size modifier, size expression, and index type qualifiers. |
| 417 | /// |
| 418 | /// By default, performs semantic analysis when building the array type. |
| 419 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | unsigned IndexTypeQuals, |
| 424 | SourceRange BracketsRange); |
| 425 | |
| 426 | /// \brief Build a new vector type given the element type and |
| 427 | /// number of elements. |
| 428 | /// |
| 429 | /// By default, performs semantic analysis when building the vector type. |
| 430 | /// Subclasses may override this routine to provide different behavior. |
| 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | /// \brief Build a new extended vector type given the element type and |
| 434 | /// number of elements. |
| 435 | /// |
| 436 | /// By default, performs semantic analysis when building the vector type. |
| 437 | /// Subclasses may override this routine to provide different behavior. |
| 438 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 439 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
| 441 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 442 | /// given the element type and number of elements. |
| 443 | /// |
| 444 | /// By default, performs semantic analysis when building the vector type. |
| 445 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 447 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 448 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new function type. |
| 451 | /// |
| 452 | /// By default, performs semantic analysis when building the function type. |
| 453 | /// Subclasses may override this routine to provide different behavior. |
| 454 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | unsigned NumParamTypes, |
| 457 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 459 | /// \brief Build a new unprototyped function type. |
| 460 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 461 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 462 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 463 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 464 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 465 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 466 | /// \brief Build a new typedef type. |
| 467 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 468 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 469 | } |
| 470 | |
| 471 | /// \brief Build a new class/struct/union type. |
| 472 | QualType RebuildRecordType(RecordDecl *Record) { |
| 473 | return SemaRef.Context.getTypeDeclType(Record); |
| 474 | } |
| 475 | |
| 476 | /// \brief Build a new Enum type. |
| 477 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 478 | return SemaRef.Context.getTypeDeclType(Enum); |
| 479 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 480 | |
| 481 | /// \brief Build a new elaborated type. |
| 482 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 483 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | |
| 486 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 487 | /// |
| 488 | /// By default, performs semantic analysis when building the typeof type. |
| 489 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 490 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 491 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | /// |
| 494 | /// By default, builds a new TypeOfType with the given underlying type. |
| 495 | QualType RebuildTypeOfType(QualType Underlying); |
| 496 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 498 | /// |
| 499 | /// By default, performs semantic analysis when building the decltype type. |
| 500 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 501 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 503 | /// \brief Build a new template specialization type. |
| 504 | /// |
| 505 | /// By default, performs semantic analysis when building the template |
| 506 | /// specialization type. Subclasses may override this routine to provide |
| 507 | /// different behavior. |
| 508 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 509 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 510 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// \brief Build a new qualified name type. |
| 513 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | /// By default, builds a new QualifiedNameType type from the |
| 515 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 516 | /// this routine to provide different behavior. |
| 517 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 518 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 520 | |
| 521 | /// \brief Build a new typename type that refers to a template-id. |
| 522 | /// |
| 523 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 525 | /// different behavior. |
| 526 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 527 | if (NNS->isDependent()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 529 | cast<TemplateSpecializationType>(T)); |
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 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | |
| 534 | /// \brief Build a new typename type that refers to an identifier. |
| 535 | /// |
| 536 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 538 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 540 | const IdentifierInfo *Id, |
| 541 | SourceRange SR) { |
| 542 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 545 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 546 | /// identifier that names the next step in the nested-name-specifier. |
| 547 | /// |
| 548 | /// By default, performs semantic analysis when building the new |
| 549 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 550 | /// different behavior. |
| 551 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 552 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 553 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 554 | QualType ObjectType, |
| 555 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 556 | |
| 557 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 558 | /// namespace named in the next step in the nested-name-specifier. |
| 559 | /// |
| 560 | /// By default, performs semantic analysis when building the new |
| 561 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 562 | /// different behavior. |
| 563 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 564 | SourceRange Range, |
| 565 | NamespaceDecl *NS); |
| 566 | |
| 567 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 568 | /// type named in the next step in the nested-name-specifier. |
| 569 | /// |
| 570 | /// By default, performs semantic analysis when building the new |
| 571 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 572 | /// different behavior. |
| 573 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 574 | SourceRange Range, |
| 575 | bool TemplateKW, |
| 576 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 577 | |
| 578 | /// \brief Build a new template name given a nested name specifier, a flag |
| 579 | /// indicating whether the "template" keyword was provided, and the template |
| 580 | /// that the template name refers to. |
| 581 | /// |
| 582 | /// By default, builds the new template name directly. Subclasses may override |
| 583 | /// this routine to provide different behavior. |
| 584 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 585 | bool TemplateKW, |
| 586 | TemplateDecl *Template); |
| 587 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 588 | /// \brief Build a new template name given a nested name specifier and the |
| 589 | /// name that is referred to as a template. |
| 590 | /// |
| 591 | /// By default, performs semantic analysis to determine whether the name can |
| 592 | /// be resolved to a specific template, then builds the appropriate kind of |
| 593 | /// template name. Subclasses may override this routine to provide different |
| 594 | /// behavior. |
| 595 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 596 | const IdentifierInfo &II, |
| 597 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 599 | /// \brief Build a new template name given a nested name specifier and the |
| 600 | /// overloaded operator name that is referred to as a template. |
| 601 | /// |
| 602 | /// By default, performs semantic analysis to determine whether the name can |
| 603 | /// be resolved to a specific template, then builds the appropriate kind of |
| 604 | /// template name. Subclasses may override this routine to provide different |
| 605 | /// behavior. |
| 606 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 607 | OverloadedOperatorKind Operator, |
| 608 | QualType ObjectType); |
| 609 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 610 | /// \brief Build a new compound statement. |
| 611 | /// |
| 612 | /// By default, performs semantic analysis to build the new statement. |
| 613 | /// Subclasses may override this routine to provide different behavior. |
| 614 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 615 | MultiStmtArg Statements, |
| 616 | SourceLocation RBraceLoc, |
| 617 | bool IsStmtExpr) { |
| 618 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 619 | IsStmtExpr); |
| 620 | } |
| 621 | |
| 622 | /// \brief Build a new case statement. |
| 623 | /// |
| 624 | /// By default, performs semantic analysis to build the new statement. |
| 625 | /// Subclasses may override this routine to provide different behavior. |
| 626 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 627 | ExprArg LHS, |
| 628 | SourceLocation EllipsisLoc, |
| 629 | ExprArg RHS, |
| 630 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 632 | ColonLoc); |
| 633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 635 | /// \brief Attach the body to a new case statement. |
| 636 | /// |
| 637 | /// By default, performs semantic analysis to build the new statement. |
| 638 | /// Subclasses may override this routine to provide different behavior. |
| 639 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 640 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 641 | return move(S); |
| 642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 644 | /// \brief Build a new default statement. |
| 645 | /// |
| 646 | /// By default, performs semantic analysis to build the new statement. |
| 647 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 649 | SourceLocation ColonLoc, |
| 650 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 652 | /*CurScope=*/0); |
| 653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 655 | /// \brief Build a new label statement. |
| 656 | /// |
| 657 | /// By default, performs semantic analysis to build the new statement. |
| 658 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 660 | IdentifierInfo *Id, |
| 661 | SourceLocation ColonLoc, |
| 662 | StmtArg SubStmt) { |
| 663 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 664 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 666 | /// \brief Build a new "if" statement. |
| 667 | /// |
| 668 | /// By default, performs semantic analysis to build the new statement. |
| 669 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 670 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 671 | VarDecl *CondVar, StmtArg Then, |
| 672 | SourceLocation ElseLoc, StmtArg Else) { |
| 673 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 674 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 675 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 677 | /// \brief Start building a new switch statement. |
| 678 | /// |
| 679 | /// By default, performs semantic analysis to build the new statement. |
| 680 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 681 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 682 | VarDecl *CondVar) { |
| 683 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 686 | /// \brief Attach the body to the switch statement. |
| 687 | /// |
| 688 | /// By default, performs semantic analysis to build the new statement. |
| 689 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 691 | StmtArg Switch, StmtArg Body) { |
| 692 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 693 | move(Body)); |
| 694 | } |
| 695 | |
| 696 | /// \brief Build a new while statement. |
| 697 | /// |
| 698 | /// By default, performs semantic analysis to build the new statement. |
| 699 | /// Subclasses may override this routine to provide different behavior. |
| 700 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 701 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 702 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 703 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 704 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 705 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 708 | /// \brief Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 713 | SourceLocation WhileLoc, |
| 714 | SourceLocation LParenLoc, |
| 715 | ExprArg Cond, |
| 716 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 718 | move(Cond), RParenLoc); |
| 719 | } |
| 720 | |
| 721 | /// \brief Build a new for statement. |
| 722 | /// |
| 723 | /// By default, performs semantic analysis to build the new statement. |
| 724 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 727 | StmtArg Init, Sema::FullExprArg Cond, |
| 728 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 729 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 730 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 731 | DeclPtrTy::make(CondVar), |
| 732 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | /// \brief Build a new goto statement. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis to build the new statement. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
| 739 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 740 | SourceLocation LabelLoc, |
| 741 | LabelStmt *Label) { |
| 742 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 743 | } |
| 744 | |
| 745 | /// \brief Build a new indirect goto statement. |
| 746 | /// |
| 747 | /// By default, performs semantic analysis to build the new statement. |
| 748 | /// Subclasses may override this routine to provide different behavior. |
| 749 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 750 | SourceLocation StarLoc, |
| 751 | ExprArg Target) { |
| 752 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 753 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 755 | /// \brief Build a new return statement. |
| 756 | /// |
| 757 | /// By default, performs semantic analysis to build the new statement. |
| 758 | /// Subclasses may override this routine to provide different behavior. |
| 759 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 760 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 762 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 763 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 765 | /// \brief Build a new declaration statement. |
| 766 | /// |
| 767 | /// By default, performs semantic analysis to build the new statement. |
| 768 | /// Subclasses may override this routine to provide different behavior. |
| 769 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 771 | SourceLocation EndLoc) { |
| 772 | return getSema().Owned( |
| 773 | new (getSema().Context) DeclStmt( |
| 774 | DeclGroupRef::Create(getSema().Context, |
| 775 | Decls, NumDecls), |
| 776 | StartLoc, EndLoc)); |
| 777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 779 | /// \brief Build a new C++ exception declaration. |
| 780 | /// |
| 781 | /// By default, performs semantic analysis to build the new decaration. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 784 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 785 | IdentifierInfo *Name, |
| 786 | SourceLocation Loc, |
| 787 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 789 | TypeRange); |
| 790 | } |
| 791 | |
| 792 | /// \brief Build a new C++ catch statement. |
| 793 | /// |
| 794 | /// By default, performs semantic analysis to build the new statement. |
| 795 | /// Subclasses may override this routine to provide different behavior. |
| 796 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 797 | VarDecl *ExceptionDecl, |
| 798 | StmtArg Handler) { |
| 799 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | Handler.takeAs<Stmt>())); |
| 802 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 804 | /// \brief Build a new C++ try statement. |
| 805 | /// |
| 806 | /// By default, performs semantic analysis to build the new statement. |
| 807 | /// Subclasses may override this routine to provide different behavior. |
| 808 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 809 | StmtArg TryBlock, |
| 810 | MultiStmtArg Handlers) { |
| 811 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 813 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 814 | /// \brief Build a new expression that references a declaration. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis to build the new expression. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 818 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 819 | LookupResult &R, |
| 820 | bool RequiresADL) { |
| 821 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 822 | } |
| 823 | |
| 824 | |
| 825 | /// \brief Build a new expression that references a declaration. |
| 826 | /// |
| 827 | /// By default, performs semantic analysis to build the new expression. |
| 828 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 829 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 830 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 831 | ValueDecl *VD, SourceLocation Loc, |
| 832 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 833 | CXXScopeSpec SS; |
| 834 | SS.setScopeRep(Qualifier); |
| 835 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 836 | |
| 837 | // FIXME: loses template args. |
| 838 | |
| 839 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 842 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 844 | /// By default, performs semantic analysis to build the new expression. |
| 845 | /// Subclasses may override this routine to provide different behavior. |
| 846 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 847 | SourceLocation RParen) { |
| 848 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 849 | } |
| 850 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 851 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 853 | /// By default, performs semantic analysis to build the new expression. |
| 854 | /// Subclasses may override this routine to provide different behavior. |
| 855 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 856 | SourceLocation OperatorLoc, |
| 857 | bool isArrow, |
| 858 | SourceLocation DestroyedTypeLoc, |
| 859 | QualType DestroyedType, |
| 860 | NestedNameSpecifier *Qualifier, |
| 861 | SourceRange QualifierRange) { |
| 862 | CXXScopeSpec SS; |
| 863 | if (Qualifier) { |
| 864 | SS.setRange(QualifierRange); |
| 865 | SS.setScopeRep(Qualifier); |
| 866 | } |
| 867 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 868 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 869 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 871 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 872 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 873 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 874 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 875 | OperatorLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 876 | SS, /*FIXME: FirstQualifier*/ 0, |
| 877 | Name, DestroyedTypeLoc, |
| 878 | /*TemplateArgs*/ 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 881 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 883 | /// By default, performs semantic analysis to build the new expression. |
| 884 | /// Subclasses may override this routine to provide different behavior. |
| 885 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 886 | UnaryOperator::Opcode Opc, |
| 887 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 888 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 889 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 893 | /// By default, performs semantic analysis to build the new expression. |
| 894 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 895 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 896 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 897 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 898 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 901 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 902 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 903 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 904 | /// By default, performs semantic analysis to build the new expression. |
| 905 | /// Subclasses may override this routine to provide different behavior. |
| 906 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 907 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 909 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 910 | OpLoc, isSizeOf, R); |
| 911 | if (Result.isInvalid()) |
| 912 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 914 | SubExpr.release(); |
| 915 | return move(Result); |
| 916 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 918 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | /// By default, performs semantic analysis to build the new expression. |
| 921 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 922 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 923 | SourceLocation LBracketLoc, |
| 924 | ExprArg RHS, |
| 925 | SourceLocation RBracketLoc) { |
| 926 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | RBracketLoc); |
| 929 | } |
| 930 | |
| 931 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 932 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 933 | /// By default, performs semantic analysis to build the new expression. |
| 934 | /// Subclasses may override this routine to provide different behavior. |
| 935 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 936 | MultiExprArg Args, |
| 937 | SourceLocation *CommaLocs, |
| 938 | SourceLocation RParenLoc) { |
| 939 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 940 | move(Args), CommaLocs, RParenLoc); |
| 941 | } |
| 942 | |
| 943 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | /// By default, performs semantic analysis to build the new expression. |
| 946 | /// Subclasses may override this routine to provide different behavior. |
| 947 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 949 | NestedNameSpecifier *Qualifier, |
| 950 | SourceRange QualifierRange, |
| 951 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 952 | ValueDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 953 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 954 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 955 | if (!Member->getDeclName()) { |
| 956 | // We have a reference to an unnamed field. |
| 957 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 959 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 960 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 961 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 962 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 964 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 965 | Member, MemberLoc, |
| 966 | cast<FieldDecl>(Member)->getType()); |
| 967 | return getSema().Owned(ME); |
| 968 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 970 | CXXScopeSpec SS; |
| 971 | if (Qualifier) { |
| 972 | SS.setRange(QualifierRange); |
| 973 | SS.setScopeRep(Qualifier); |
| 974 | } |
| 975 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 976 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 977 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 978 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 979 | Sema::LookupMemberName); |
| 980 | R.addDecl(Member); |
| 981 | R.resolveKind(); |
| 982 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 983 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 984 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 985 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 986 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 987 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 989 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | /// By default, performs semantic analysis to build the new expression. |
| 992 | /// Subclasses may override this routine to provide different behavior. |
| 993 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 994 | BinaryOperator::Opcode Opc, |
| 995 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 996 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 997 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1002 | /// By default, performs semantic analysis to build the new expression. |
| 1003 | /// Subclasses may override this routine to provide different behavior. |
| 1004 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1005 | SourceLocation QuestionLoc, |
| 1006 | ExprArg LHS, |
| 1007 | SourceLocation ColonLoc, |
| 1008 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | move(LHS), move(RHS)); |
| 1011 | } |
| 1012 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1013 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1015 | /// By default, performs semantic analysis to build the new expression. |
| 1016 | /// Subclasses may override this routine to provide different behavior. |
| 1017 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1018 | QualType ExplicitTy, |
| 1019 | SourceLocation RParenLoc, |
| 1020 | ExprArg SubExpr) { |
| 1021 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1022 | LParenLoc, |
| 1023 | ExplicitTy.getAsOpaquePtr(), |
| 1024 | RParenLoc, |
| 1025 | move(SubExpr)); |
| 1026 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1028 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1029 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1030 | /// By default, performs semantic analysis to build the new expression. |
| 1031 | /// Subclasses may override this routine to provide different behavior. |
| 1032 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1033 | QualType T, |
| 1034 | SourceLocation RParenLoc, |
| 1035 | ExprArg Init) { |
| 1036 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1037 | RParenLoc, move(Init)); |
| 1038 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1040 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | /// By default, performs semantic analysis to build the new expression. |
| 1043 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1044 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | SourceLocation OpLoc, |
| 1046 | SourceLocation AccessorLoc, |
| 1047 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1048 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1049 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1050 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1051 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1052 | OpLoc, /*IsArrow*/ false, |
| 1053 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1054 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1055 | AccessorLoc, |
| 1056 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1059 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1061 | /// By default, performs semantic analysis to build the new expression. |
| 1062 | /// Subclasses may override this routine to provide different behavior. |
| 1063 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1064 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1065 | SourceLocation RBraceLoc, |
| 1066 | QualType ResultTy) { |
| 1067 | OwningExprResult Result |
| 1068 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1069 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1070 | return move(Result); |
| 1071 | |
| 1072 | // Patch in the result type we were given, which may have been computed |
| 1073 | // when the initial InitListExpr was built. |
| 1074 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1075 | ILE->setType(ResultTy); |
| 1076 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1079 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1081 | /// By default, performs semantic analysis to build the new expression. |
| 1082 | /// Subclasses may override this routine to provide different behavior. |
| 1083 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1084 | MultiExprArg ArrayExprs, |
| 1085 | SourceLocation EqualOrColonLoc, |
| 1086 | bool GNUSyntax, |
| 1087 | ExprArg Init) { |
| 1088 | OwningExprResult Result |
| 1089 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1090 | move(Init)); |
| 1091 | if (Result.isInvalid()) |
| 1092 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1094 | ArrayExprs.release(); |
| 1095 | return move(Result); |
| 1096 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1099 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | /// By default, builds the implicit value initialization without performing |
| 1101 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1102 | /// different behavior. |
| 1103 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1104 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1107 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | /// By default, performs semantic analysis to build the new expression. |
| 1110 | /// Subclasses may override this routine to provide different behavior. |
| 1111 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1112 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1114 | RParenLoc); |
| 1115 | } |
| 1116 | |
| 1117 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1119 | /// By default, performs semantic analysis to build the new expression. |
| 1120 | /// Subclasses may override this routine to provide different behavior. |
| 1121 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1122 | MultiExprArg SubExprs, |
| 1123 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1124 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1125 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | /// |
| 1130 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1131 | /// rather than attempting to map the label statement itself. |
| 1132 | /// Subclasses may override this routine to provide different behavior. |
| 1133 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1134 | SourceLocation LabelLoc, |
| 1135 | LabelStmt *Label) { |
| 1136 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | /// By default, performs semantic analysis to build the new expression. |
| 1142 | /// Subclasses may override this routine to provide different behavior. |
| 1143 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1144 | StmtArg SubStmt, |
| 1145 | SourceLocation RParenLoc) { |
| 1146 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1149 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1150 | /// |
| 1151 | /// By default, performs semantic analysis to build the new expression. |
| 1152 | /// Subclasses may override this routine to provide different behavior. |
| 1153 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1154 | QualType T1, QualType T2, |
| 1155 | SourceLocation RParenLoc) { |
| 1156 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1157 | T1.getAsOpaquePtr(), |
| 1158 | T2.getAsOpaquePtr(), |
| 1159 | RParenLoc); |
| 1160 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1162 | /// \brief Build a new __builtin_choose_expr expression. |
| 1163 | /// |
| 1164 | /// By default, performs semantic analysis to build the new expression. |
| 1165 | /// Subclasses may override this routine to provide different behavior. |
| 1166 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1167 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1168 | SourceLocation RParenLoc) { |
| 1169 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1170 | move(Cond), move(LHS), move(RHS), |
| 1171 | RParenLoc); |
| 1172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1174 | /// \brief Build a new overloaded operator call expression. |
| 1175 | /// |
| 1176 | /// By default, performs semantic analysis to build the new expression. |
| 1177 | /// The semantic analysis provides the behavior of template instantiation, |
| 1178 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1180 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1181 | /// provide different behavior. |
| 1182 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1183 | SourceLocation OpLoc, |
| 1184 | ExprArg Callee, |
| 1185 | ExprArg First, |
| 1186 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
| 1188 | /// \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] | 1189 | /// reinterpret_cast. |
| 1190 | /// |
| 1191 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | /// Subclasses may override this routine to provide different behavior. |
| 1194 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1195 | Stmt::StmtClass Class, |
| 1196 | SourceLocation LAngleLoc, |
| 1197 | QualType T, |
| 1198 | SourceLocation RAngleLoc, |
| 1199 | SourceLocation LParenLoc, |
| 1200 | ExprArg SubExpr, |
| 1201 | SourceLocation RParenLoc) { |
| 1202 | switch (Class) { |
| 1203 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1204 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1205 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | move(SubExpr), RParenLoc); |
| 1207 | |
| 1208 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1210 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1211 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1215 | RAngleLoc, LParenLoc, |
| 1216 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1221 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | default: |
| 1225 | assert(false && "Invalid C++ named cast"); |
| 1226 | break; |
| 1227 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1229 | return getSema().ExprError(); |
| 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 C++ static_cast expression. |
| 1233 | /// |
| 1234 | /// By default, performs semantic analysis to build the new expression. |
| 1235 | /// Subclasses may override this routine to provide different behavior. |
| 1236 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1237 | SourceLocation LAngleLoc, |
| 1238 | QualType T, |
| 1239 | SourceLocation RAngleLoc, |
| 1240 | SourceLocation LParenLoc, |
| 1241 | ExprArg SubExpr, |
| 1242 | SourceLocation RParenLoc) { |
| 1243 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | LParenLoc, move(SubExpr), RParenLoc); |
| 1246 | } |
| 1247 | |
| 1248 | /// \brief Build a new C++ dynamic_cast expression. |
| 1249 | /// |
| 1250 | /// By default, performs semantic analysis to build the new expression. |
| 1251 | /// Subclasses may override this routine to provide different behavior. |
| 1252 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1253 | SourceLocation LAngleLoc, |
| 1254 | QualType T, |
| 1255 | SourceLocation RAngleLoc, |
| 1256 | SourceLocation LParenLoc, |
| 1257 | ExprArg SubExpr, |
| 1258 | SourceLocation RParenLoc) { |
| 1259 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | LParenLoc, move(SubExpr), RParenLoc); |
| 1262 | } |
| 1263 | |
| 1264 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1265 | /// |
| 1266 | /// By default, performs semantic analysis to build the new expression. |
| 1267 | /// Subclasses may override this routine to provide different behavior. |
| 1268 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1269 | SourceLocation LAngleLoc, |
| 1270 | QualType T, |
| 1271 | SourceLocation RAngleLoc, |
| 1272 | SourceLocation LParenLoc, |
| 1273 | ExprArg SubExpr, |
| 1274 | SourceLocation RParenLoc) { |
| 1275 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1276 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1277 | LParenLoc, move(SubExpr), RParenLoc); |
| 1278 | } |
| 1279 | |
| 1280 | /// \brief Build a new C++ const_cast expression. |
| 1281 | /// |
| 1282 | /// By default, performs semantic analysis to build the new expression. |
| 1283 | /// Subclasses may override this routine to provide different behavior. |
| 1284 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1285 | SourceLocation LAngleLoc, |
| 1286 | QualType T, |
| 1287 | SourceLocation RAngleLoc, |
| 1288 | SourceLocation LParenLoc, |
| 1289 | ExprArg SubExpr, |
| 1290 | SourceLocation RParenLoc) { |
| 1291 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1293 | LParenLoc, move(SubExpr), RParenLoc); |
| 1294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | /// \brief Build a new C++ functional-style cast expression. |
| 1297 | /// |
| 1298 | /// By default, performs semantic analysis to build the new expression. |
| 1299 | /// Subclasses may override this routine to provide different behavior. |
| 1300 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1301 | QualType T, |
| 1302 | SourceLocation LParenLoc, |
| 1303 | ExprArg SubExpr, |
| 1304 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1305 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1306 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1307 | T.getAsOpaquePtr(), |
| 1308 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1309 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | RParenLoc); |
| 1312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | /// \brief Build a new C++ typeid(type) expression. |
| 1315 | /// |
| 1316 | /// By default, performs semantic analysis to build the new expression. |
| 1317 | /// Subclasses may override this routine to provide different behavior. |
| 1318 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1319 | SourceLocation LParenLoc, |
| 1320 | QualType T, |
| 1321 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | T.getAsOpaquePtr(), RParenLoc); |
| 1324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// \brief Build a new C++ typeid(expr) expression. |
| 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new expression. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1331 | SourceLocation LParenLoc, |
| 1332 | ExprArg Operand, |
| 1333 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1334 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1336 | RParenLoc); |
| 1337 | if (Result.isInvalid()) |
| 1338 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1339 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1340 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1341 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | /// \brief Build a new C++ "this" expression. |
| 1345 | /// |
| 1346 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1348 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1350 | QualType ThisType, |
| 1351 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1352 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1353 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1354 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /// \brief Build a new C++ throw expression. |
| 1358 | /// |
| 1359 | /// By default, performs semantic analysis to build the new expression. |
| 1360 | /// Subclasses may override this routine to provide different behavior. |
| 1361 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1362 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1363 | } |
| 1364 | |
| 1365 | /// \brief Build a new C++ default-argument expression. |
| 1366 | /// |
| 1367 | /// By default, builds a new default-argument expression, which does not |
| 1368 | /// require any semantic analysis. Subclasses may override this routine to |
| 1369 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1370 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1371 | ParmVarDecl *Param) { |
| 1372 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1373 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | /// \brief Build a new C++ zero-initialization expression. |
| 1377 | /// |
| 1378 | /// By default, performs semantic analysis to build the new expression. |
| 1379 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1380 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1381 | SourceLocation LParenLoc, |
| 1382 | QualType T, |
| 1383 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1384 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1385 | T.getAsOpaquePtr(), LParenLoc, |
| 1386 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1387 | 0, RParenLoc); |
| 1388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1390 | /// \brief Build a new C++ "new" expression. |
| 1391 | /// |
| 1392 | /// By default, performs semantic analysis to build the new expression. |
| 1393 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1395 | bool UseGlobal, |
| 1396 | SourceLocation PlacementLParen, |
| 1397 | MultiExprArg PlacementArgs, |
| 1398 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | QualType AllocType, |
| 1401 | SourceLocation TypeLoc, |
| 1402 | SourceRange TypeRange, |
| 1403 | ExprArg ArraySize, |
| 1404 | SourceLocation ConstructorLParen, |
| 1405 | MultiExprArg ConstructorArgs, |
| 1406 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | PlacementLParen, |
| 1409 | move(PlacementArgs), |
| 1410 | PlacementRParen, |
| 1411 | ParenTypeId, |
| 1412 | AllocType, |
| 1413 | TypeLoc, |
| 1414 | TypeRange, |
| 1415 | move(ArraySize), |
| 1416 | ConstructorLParen, |
| 1417 | move(ConstructorArgs), |
| 1418 | ConstructorRParen); |
| 1419 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1421 | /// \brief Build a new C++ "delete" expression. |
| 1422 | /// |
| 1423 | /// By default, performs semantic analysis to build the new expression. |
| 1424 | /// Subclasses may override this routine to provide different behavior. |
| 1425 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1426 | bool IsGlobalDelete, |
| 1427 | bool IsArrayForm, |
| 1428 | ExprArg Operand) { |
| 1429 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1430 | move(Operand)); |
| 1431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1432 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1433 | /// \brief Build a new unary type trait expression. |
| 1434 | /// |
| 1435 | /// By default, performs semantic analysis to build the new expression. |
| 1436 | /// Subclasses may override this routine to provide different behavior. |
| 1437 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1438 | SourceLocation StartLoc, |
| 1439 | SourceLocation LParenLoc, |
| 1440 | QualType T, |
| 1441 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1442 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | T.getAsOpaquePtr(), RParenLoc); |
| 1444 | } |
| 1445 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | /// expression. |
| 1448 | /// |
| 1449 | /// By default, performs semantic analysis to build the new expression. |
| 1450 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1451 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1452 | SourceRange QualifierRange, |
| 1453 | DeclarationName Name, |
| 1454 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1455 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | CXXScopeSpec SS; |
| 1457 | SS.setRange(QualifierRange); |
| 1458 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1459 | |
| 1460 | if (TemplateArgs) |
| 1461 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1462 | *TemplateArgs); |
| 1463 | |
| 1464 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | /// \brief Build a new template-id expression. |
| 1468 | /// |
| 1469 | /// By default, performs semantic analysis to build the new expression. |
| 1470 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1471 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1472 | LookupResult &R, |
| 1473 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1474 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1475 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /// \brief Build a new object-construction expression. |
| 1479 | /// |
| 1480 | /// By default, performs semantic analysis to build the new expression. |
| 1481 | /// Subclasses may override this routine to provide different behavior. |
| 1482 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1483 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | CXXConstructorDecl *Constructor, |
| 1485 | bool IsElidable, |
| 1486 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1487 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1488 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1489 | ConvertedArgs)) |
| 1490 | return getSema().ExprError(); |
| 1491 | |
| 1492 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1493 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | /// \brief Build a new object-construction expression. |
| 1497 | /// |
| 1498 | /// By default, performs semantic analysis to build the new expression. |
| 1499 | /// Subclasses may override this routine to provide different behavior. |
| 1500 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1501 | QualType T, |
| 1502 | SourceLocation LParenLoc, |
| 1503 | MultiExprArg Args, |
| 1504 | SourceLocation *Commas, |
| 1505 | SourceLocation RParenLoc) { |
| 1506 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1507 | T.getAsOpaquePtr(), |
| 1508 | LParenLoc, |
| 1509 | move(Args), |
| 1510 | Commas, |
| 1511 | RParenLoc); |
| 1512 | } |
| 1513 | |
| 1514 | /// \brief Build a new object-construction expression. |
| 1515 | /// |
| 1516 | /// By default, performs semantic analysis to build the new expression. |
| 1517 | /// Subclasses may override this routine to provide different behavior. |
| 1518 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1519 | QualType T, |
| 1520 | SourceLocation LParenLoc, |
| 1521 | MultiExprArg Args, |
| 1522 | SourceLocation *Commas, |
| 1523 | SourceLocation RParenLoc) { |
| 1524 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1525 | /*FIXME*/LParenLoc), |
| 1526 | T.getAsOpaquePtr(), |
| 1527 | LParenLoc, |
| 1528 | move(Args), |
| 1529 | Commas, |
| 1530 | RParenLoc); |
| 1531 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1532 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | /// \brief Build a new member reference expression. |
| 1534 | /// |
| 1535 | /// By default, performs semantic analysis to build the new expression. |
| 1536 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1537 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1538 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | bool IsArrow, |
| 1540 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1541 | NestedNameSpecifier *Qualifier, |
| 1542 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1543 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1545 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1546 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1547 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1548 | SS.setRange(QualifierRange); |
| 1549 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1551 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1552 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1553 | SS, FirstQualifierInScope, |
| 1554 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1557 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1558 | /// |
| 1559 | /// By default, performs semantic analysis to build the new expression. |
| 1560 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1561 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1562 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1563 | SourceLocation OperatorLoc, |
| 1564 | bool IsArrow, |
| 1565 | NestedNameSpecifier *Qualifier, |
| 1566 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 1567 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1568 | LookupResult &R, |
| 1569 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1570 | CXXScopeSpec SS; |
| 1571 | SS.setRange(QualifierRange); |
| 1572 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1574 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1575 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 1576 | SS, FirstQualifierInScope, |
| 1577 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1578 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1579 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1580 | /// \brief Build a new Objective-C @encode expression. |
| 1581 | /// |
| 1582 | /// By default, performs semantic analysis to build the new expression. |
| 1583 | /// Subclasses may override this routine to provide different behavior. |
| 1584 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1585 | QualType T, |
| 1586 | SourceLocation RParenLoc) { |
| 1587 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1588 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1589 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1590 | |
| 1591 | /// \brief Build a new Objective-C protocol expression. |
| 1592 | /// |
| 1593 | /// By default, performs semantic analysis to build the new expression. |
| 1594 | /// Subclasses may override this routine to provide different behavior. |
| 1595 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1596 | SourceLocation AtLoc, |
| 1597 | SourceLocation ProtoLoc, |
| 1598 | SourceLocation LParenLoc, |
| 1599 | SourceLocation RParenLoc) { |
| 1600 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1601 | Protocol->getIdentifier(), |
| 1602 | AtLoc, |
| 1603 | ProtoLoc, |
| 1604 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | /// \brief Build a new shuffle vector expression. |
| 1609 | /// |
| 1610 | /// By default, performs semantic analysis to build the new expression. |
| 1611 | /// Subclasses may override this routine to provide different behavior. |
| 1612 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1613 | MultiExprArg SubExprs, |
| 1614 | SourceLocation RParenLoc) { |
| 1615 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1616 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1618 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1619 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1620 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | // Build a reference to the __builtin_shufflevector builtin |
| 1623 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1626 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1627 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1628 | |
| 1629 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | unsigned NumSubExprs = SubExprs.size(); |
| 1631 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1632 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1633 | Subs, NumSubExprs, |
| 1634 | Builtin->getResultType(), |
| 1635 | RParenLoc); |
| 1636 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1638 | // Type-check the __builtin_shufflevector expression. |
| 1639 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1640 | if (Result.isInvalid()) |
| 1641 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1642 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1646 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1648 | template<typename Derived> |
| 1649 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1650 | if (!S) |
| 1651 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1653 | switch (S->getStmtClass()) { |
| 1654 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1656 | // Transform individual statement nodes |
| 1657 | #define STMT(Node, Parent) \ |
| 1658 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1659 | #define EXPR(Node, Parent) |
| 1660 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1661 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1662 | // Transform expressions by calling TransformExpr. |
| 1663 | #define STMT(Node, Parent) |
| 1664 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1665 | #include "clang/AST/StmtNodes.def" |
| 1666 | { |
| 1667 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1668 | if (E.isInvalid()) |
| 1669 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1671 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1672 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1675 | return SemaRef.Owned(S->Retain()); |
| 1676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1677 | |
| 1678 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1679 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1680 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | if (!E) |
| 1682 | return SemaRef.Owned(E); |
| 1683 | |
| 1684 | switch (E->getStmtClass()) { |
| 1685 | case Stmt::NoStmtClass: break; |
| 1686 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1687 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1688 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1692 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1696 | NestedNameSpecifier * |
| 1697 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1698 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1699 | QualType ObjectType, |
| 1700 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1701 | if (!NNS) |
| 1702 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1703 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1704 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1705 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1706 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1707 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1708 | ObjectType, |
| 1709 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1710 | if (!Prefix) |
| 1711 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1712 | |
| 1713 | // 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] | 1714 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1715 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1716 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1719 | switch (NNS->getKind()) { |
| 1720 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1722 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1723 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1724 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1725 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1726 | |
| 1727 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1728 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1729 | ObjectType, |
| 1730 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1732 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1734 | = cast_or_null<NamespaceDecl>( |
| 1735 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1737 | Prefix == NNS->getPrefix() && |
| 1738 | NS == NNS->getAsNamespace()) |
| 1739 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1741 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1742 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1744 | case NestedNameSpecifier::Global: |
| 1745 | // There is no meaningful transformation that one could perform on the |
| 1746 | // global scope. |
| 1747 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1749 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1750 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1751 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1752 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1753 | if (T.isNull()) |
| 1754 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1756 | if (!getDerived().AlwaysRebuild() && |
| 1757 | Prefix == NNS->getPrefix() && |
| 1758 | T == QualType(NNS->getAsType(), 0)) |
| 1759 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
| 1761 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1762 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1763 | T); |
| 1764 | } |
| 1765 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1773 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1774 | SourceLocation Loc, |
| 1775 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1776 | if (!Name) |
| 1777 | return Name; |
| 1778 | |
| 1779 | switch (Name.getNameKind()) { |
| 1780 | case DeclarationName::Identifier: |
| 1781 | case DeclarationName::ObjCZeroArgSelector: |
| 1782 | case DeclarationName::ObjCOneArgSelector: |
| 1783 | case DeclarationName::ObjCMultiArgSelector: |
| 1784 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1785 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1786 | case DeclarationName::CXXUsingDirective: |
| 1787 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1788 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1789 | case DeclarationName::CXXConstructorName: |
| 1790 | case DeclarationName::CXXDestructorName: |
| 1791 | case DeclarationName::CXXConversionFunctionName: { |
| 1792 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1793 | QualType T; |
| 1794 | if (!ObjectType.isNull() && |
| 1795 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1796 | TemplateSpecializationType *SpecType |
| 1797 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1798 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1799 | } else |
| 1800 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1801 | if (T.isNull()) |
| 1802 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1804 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1807 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1810 | return DeclarationName(); |
| 1811 | } |
| 1812 | |
| 1813 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1815 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1816 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1817 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1819 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1820 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1821 | if (!NNS) |
| 1822 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1824 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1826 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1827 | if (!TransTemplate) |
| 1828 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1830 | if (!getDerived().AlwaysRebuild() && |
| 1831 | NNS == QTN->getQualifier() && |
| 1832 | TransTemplate == Template) |
| 1833 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1835 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1836 | TransTemplate); |
| 1837 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1839 | // These should be getting filtered out before they make it into the AST. |
| 1840 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1841 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1843 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1845 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1846 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1847 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1848 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1851 | NNS == DTN->getQualifier() && |
| 1852 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1855 | if (DTN->isIdentifier()) |
| 1856 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1857 | ObjectType); |
| 1858 | |
| 1859 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1860 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1861 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1863 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1865 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1866 | if (!TransTemplate) |
| 1867 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1869 | if (!getDerived().AlwaysRebuild() && |
| 1870 | TransTemplate == Template) |
| 1871 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1873 | return TemplateName(TransTemplate); |
| 1874 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1876 | // These should be getting filtered out before they reach the AST. |
| 1877 | assert(false && "overloaded function decl survived to here"); |
| 1878 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1882 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1883 | const TemplateArgument &Arg, |
| 1884 | TemplateArgumentLoc &Output) { |
| 1885 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1886 | switch (Arg.getKind()) { |
| 1887 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1888 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1889 | break; |
| 1890 | |
| 1891 | case TemplateArgument::Type: |
| 1892 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1893 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1894 | |
| 1895 | break; |
| 1896 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1897 | case TemplateArgument::Template: |
| 1898 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1899 | break; |
| 1900 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1901 | case TemplateArgument::Expression: |
| 1902 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1903 | break; |
| 1904 | |
| 1905 | case TemplateArgument::Declaration: |
| 1906 | case TemplateArgument::Integral: |
| 1907 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1908 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1909 | break; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | template<typename Derived> |
| 1914 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1915 | const TemplateArgumentLoc &Input, |
| 1916 | TemplateArgumentLoc &Output) { |
| 1917 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1918 | switch (Arg.getKind()) { |
| 1919 | case TemplateArgument::Null: |
| 1920 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1921 | Output = Input; |
| 1922 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1923 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1924 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1925 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1926 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1927 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1928 | |
| 1929 | DI = getDerived().TransformType(DI); |
| 1930 | if (!DI) return true; |
| 1931 | |
| 1932 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1933 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1935 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1936 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1937 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1938 | DeclarationName Name; |
| 1939 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1940 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1941 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1942 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1943 | if (!D) return true; |
| 1944 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1945 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1946 | if (SourceExpr) { |
| 1947 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1948 | Action::Unevaluated); |
| 1949 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1950 | if (E.isInvalid()) |
| 1951 | SourceExpr = NULL; |
| 1952 | else { |
| 1953 | SourceExpr = E.takeAs<Expr>(); |
| 1954 | SourceExpr->Retain(); |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1959 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1962 | case TemplateArgument::Template: { |
| 1963 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1964 | TemplateName Template |
| 1965 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1966 | if (Template.isNull()) |
| 1967 | return true; |
| 1968 | |
| 1969 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1970 | Input.getTemplateQualifierRange(), |
| 1971 | Input.getTemplateNameLoc()); |
| 1972 | return false; |
| 1973 | } |
| 1974 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1975 | case TemplateArgument::Expression: { |
| 1976 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1978 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1980 | Expr *InputExpr = Input.getSourceExpression(); |
| 1981 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1982 | |
| 1983 | Sema::OwningExprResult E |
| 1984 | = getDerived().TransformExpr(InputExpr); |
| 1985 | if (E.isInvalid()) return true; |
| 1986 | |
| 1987 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1988 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1989 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1990 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1993 | case TemplateArgument::Pack: { |
| 1994 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 1995 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1997 | AEnd = Arg.pack_end(); |
| 1998 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2000 | // FIXME: preserve source information here when we start |
| 2001 | // caring about parameter packs. |
| 2002 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2003 | TemplateArgumentLoc InputArg; |
| 2004 | TemplateArgumentLoc OutputArg; |
| 2005 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2006 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2007 | return true; |
| 2008 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2009 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2010 | } |
| 2011 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2013 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2014 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2015 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2016 | } |
| 2017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2019 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2020 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2023 | //===----------------------------------------------------------------------===// |
| 2024 | // Type transformation |
| 2025 | //===----------------------------------------------------------------------===// |
| 2026 | |
| 2027 | template<typename Derived> |
| 2028 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2029 | if (getDerived().AlreadyTransformed(T)) |
| 2030 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2032 | // Temporary workaround. All of these transformations should |
| 2033 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2034 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2035 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2036 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2037 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2038 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2039 | if (!NewDI) |
| 2040 | return QualType(); |
| 2041 | |
| 2042 | return NewDI->getType(); |
| 2043 | } |
| 2044 | |
| 2045 | template<typename Derived> |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2046 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2047 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2048 | return DI; |
| 2049 | |
| 2050 | TypeLocBuilder TLB; |
| 2051 | |
| 2052 | TypeLoc TL = DI->getTypeLoc(); |
| 2053 | TLB.reserve(TL.getFullDataSize()); |
| 2054 | |
| 2055 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2056 | if (Result.isNull()) |
| 2057 | return 0; |
| 2058 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2059 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | template<typename Derived> |
| 2063 | QualType |
| 2064 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2065 | switch (T.getTypeLocClass()) { |
| 2066 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2067 | #define TYPELOC(CLASS, PARENT) \ |
| 2068 | case TypeLoc::CLASS: \ |
| 2069 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2070 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2071 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2072 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2073 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2074 | return QualType(); |
| 2075 | } |
| 2076 | |
| 2077 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2078 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2079 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2080 | /// types). This is the right thing for template instantiation, but |
| 2081 | /// probably not for other clients. |
| 2082 | template<typename Derived> |
| 2083 | QualType |
| 2084 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2085 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2086 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2087 | |
| 2088 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2089 | if (Result.isNull()) |
| 2090 | return QualType(); |
| 2091 | |
| 2092 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2093 | // FIXME: this is the right thing for template instantiation, but |
| 2094 | // probably not for other clients. |
| 2095 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2096 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2097 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2098 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2099 | |
| 2100 | TLB.push<QualifiedTypeLoc>(Result); |
| 2101 | |
| 2102 | // No location information to preserve. |
| 2103 | |
| 2104 | return Result; |
| 2105 | } |
| 2106 | |
| 2107 | template <class TyLoc> static inline |
| 2108 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2109 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2110 | NewT.setNameLoc(T.getNameLoc()); |
| 2111 | return T.getType(); |
| 2112 | } |
| 2113 | |
| 2114 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2115 | // the equivalent template version work. |
| 2116 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2117 | QualType PointeeType \ |
| 2118 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2119 | if (PointeeType.isNull()) \ |
| 2120 | return QualType(); \ |
| 2121 | \ |
| 2122 | QualType Result = TL.getType(); \ |
| 2123 | if (getDerived().AlwaysRebuild() || \ |
| 2124 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2125 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2126 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2127 | if (Result.isNull()) \ |
| 2128 | return QualType(); \ |
| 2129 | } \ |
| 2130 | \ |
| 2131 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2132 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2133 | \ |
| 2134 | return Result; \ |
| 2135 | } while(0) |
| 2136 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2137 | template<typename Derived> |
| 2138 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2139 | BuiltinTypeLoc T) { |
| 2140 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2141 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2142 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2143 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2144 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2145 | ComplexTypeLoc T) { |
| 2146 | // FIXME: recurse? |
| 2147 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2149 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2150 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2151 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2152 | PointerTypeLoc TL) { |
| 2153 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2154 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2155 | |
| 2156 | template<typename Derived> |
| 2157 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2158 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2159 | BlockPointerTypeLoc TL) { |
| 2160 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2163 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2164 | /// don't care whether the type itself is an l-value type or an r-value |
| 2165 | /// type; we only care if the type was *written* as an l-value type |
| 2166 | /// or an r-value type. |
| 2167 | template<typename Derived> |
| 2168 | QualType |
| 2169 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2170 | ReferenceTypeLoc TL) { |
| 2171 | const ReferenceType *T = TL.getTypePtr(); |
| 2172 | |
| 2173 | // Note that this works with the pointee-as-written. |
| 2174 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2175 | if (PointeeType.isNull()) |
| 2176 | return QualType(); |
| 2177 | |
| 2178 | QualType Result = TL.getType(); |
| 2179 | if (getDerived().AlwaysRebuild() || |
| 2180 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2181 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2182 | T->isSpelledAsLValue(), |
| 2183 | TL.getSigilLoc()); |
| 2184 | if (Result.isNull()) |
| 2185 | return QualType(); |
| 2186 | } |
| 2187 | |
| 2188 | // r-value references can be rebuilt as l-value references. |
| 2189 | ReferenceTypeLoc NewTL; |
| 2190 | if (isa<LValueReferenceType>(Result)) |
| 2191 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2192 | else |
| 2193 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2194 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2195 | |
| 2196 | return Result; |
| 2197 | } |
| 2198 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | template<typename Derived> |
| 2200 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2201 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2202 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2203 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2206 | template<typename Derived> |
| 2207 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2208 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2209 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2210 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2211 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2213 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2214 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2215 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2216 | MemberPointerTypeLoc TL) { |
| 2217 | MemberPointerType *T = TL.getTypePtr(); |
| 2218 | |
| 2219 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2220 | if (PointeeType.isNull()) |
| 2221 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2223 | // TODO: preserve source information for this. |
| 2224 | QualType ClassType |
| 2225 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2226 | if (ClassType.isNull()) |
| 2227 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2228 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2229 | QualType Result = TL.getType(); |
| 2230 | if (getDerived().AlwaysRebuild() || |
| 2231 | PointeeType != T->getPointeeType() || |
| 2232 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2233 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2234 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2235 | if (Result.isNull()) |
| 2236 | return QualType(); |
| 2237 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2238 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2239 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2240 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2241 | |
| 2242 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2245 | template<typename Derived> |
| 2246 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2247 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2248 | ConstantArrayTypeLoc TL) { |
| 2249 | ConstantArrayType *T = TL.getTypePtr(); |
| 2250 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2251 | if (ElementType.isNull()) |
| 2252 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2253 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2254 | QualType Result = TL.getType(); |
| 2255 | if (getDerived().AlwaysRebuild() || |
| 2256 | ElementType != T->getElementType()) { |
| 2257 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2258 | T->getSizeModifier(), |
| 2259 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2260 | T->getIndexTypeCVRQualifiers(), |
| 2261 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2262 | if (Result.isNull()) |
| 2263 | return QualType(); |
| 2264 | } |
| 2265 | |
| 2266 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2267 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2268 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2269 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2270 | Expr *Size = TL.getSizeExpr(); |
| 2271 | if (Size) { |
| 2272 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2273 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2274 | } |
| 2275 | NewTL.setSizeExpr(Size); |
| 2276 | |
| 2277 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2279 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2280 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2281 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2282 | TypeLocBuilder &TLB, |
| 2283 | IncompleteArrayTypeLoc TL) { |
| 2284 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2285 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2286 | if (ElementType.isNull()) |
| 2287 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2288 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2289 | QualType Result = TL.getType(); |
| 2290 | if (getDerived().AlwaysRebuild() || |
| 2291 | ElementType != T->getElementType()) { |
| 2292 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2293 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2294 | T->getIndexTypeCVRQualifiers(), |
| 2295 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2296 | if (Result.isNull()) |
| 2297 | return QualType(); |
| 2298 | } |
| 2299 | |
| 2300 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2301 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2302 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2303 | NewTL.setSizeExpr(0); |
| 2304 | |
| 2305 | return Result; |
| 2306 | } |
| 2307 | |
| 2308 | template<typename Derived> |
| 2309 | QualType |
| 2310 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2311 | VariableArrayTypeLoc TL) { |
| 2312 | VariableArrayType *T = TL.getTypePtr(); |
| 2313 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2314 | if (ElementType.isNull()) |
| 2315 | return QualType(); |
| 2316 | |
| 2317 | // Array bounds are not potentially evaluated contexts |
| 2318 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2319 | |
| 2320 | Sema::OwningExprResult SizeResult |
| 2321 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2322 | if (SizeResult.isInvalid()) |
| 2323 | return QualType(); |
| 2324 | |
| 2325 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2326 | |
| 2327 | QualType Result = TL.getType(); |
| 2328 | if (getDerived().AlwaysRebuild() || |
| 2329 | ElementType != T->getElementType() || |
| 2330 | Size != T->getSizeExpr()) { |
| 2331 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2332 | T->getSizeModifier(), |
| 2333 | move(SizeResult), |
| 2334 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2335 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2336 | if (Result.isNull()) |
| 2337 | return QualType(); |
| 2338 | } |
| 2339 | else SizeResult.take(); |
| 2340 | |
| 2341 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2342 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2343 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2344 | NewTL.setSizeExpr(Size); |
| 2345 | |
| 2346 | return Result; |
| 2347 | } |
| 2348 | |
| 2349 | template<typename Derived> |
| 2350 | QualType |
| 2351 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2352 | DependentSizedArrayTypeLoc TL) { |
| 2353 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2354 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2355 | if (ElementType.isNull()) |
| 2356 | return QualType(); |
| 2357 | |
| 2358 | // Array bounds are not potentially evaluated contexts |
| 2359 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2360 | |
| 2361 | Sema::OwningExprResult SizeResult |
| 2362 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2363 | if (SizeResult.isInvalid()) |
| 2364 | return QualType(); |
| 2365 | |
| 2366 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2367 | |
| 2368 | QualType Result = TL.getType(); |
| 2369 | if (getDerived().AlwaysRebuild() || |
| 2370 | ElementType != T->getElementType() || |
| 2371 | Size != T->getSizeExpr()) { |
| 2372 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2373 | T->getSizeModifier(), |
| 2374 | move(SizeResult), |
| 2375 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2376 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2377 | if (Result.isNull()) |
| 2378 | return QualType(); |
| 2379 | } |
| 2380 | else SizeResult.take(); |
| 2381 | |
| 2382 | // We might have any sort of array type now, but fortunately they |
| 2383 | // all have the same location layout. |
| 2384 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2385 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2386 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2387 | NewTL.setSizeExpr(Size); |
| 2388 | |
| 2389 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2391 | |
| 2392 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2393 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2394 | TypeLocBuilder &TLB, |
| 2395 | DependentSizedExtVectorTypeLoc TL) { |
| 2396 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2397 | |
| 2398 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2399 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2400 | if (ElementType.isNull()) |
| 2401 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2402 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2403 | // Vector sizes are not potentially evaluated contexts |
| 2404 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2405 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2406 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2407 | if (Size.isInvalid()) |
| 2408 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2409 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2410 | QualType Result = TL.getType(); |
| 2411 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2412 | ElementType != T->getElementType() || |
| 2413 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2414 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2415 | move(Size), |
| 2416 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2417 | if (Result.isNull()) |
| 2418 | return QualType(); |
| 2419 | } |
| 2420 | else Size.take(); |
| 2421 | |
| 2422 | // Result might be dependent or not. |
| 2423 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2424 | DependentSizedExtVectorTypeLoc NewTL |
| 2425 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2426 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2427 | } else { |
| 2428 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2429 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2430 | } |
| 2431 | |
| 2432 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2433 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2434 | |
| 2435 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2436 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2437 | VectorTypeLoc TL) { |
| 2438 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2439 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2440 | if (ElementType.isNull()) |
| 2441 | return QualType(); |
| 2442 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2443 | QualType Result = TL.getType(); |
| 2444 | if (getDerived().AlwaysRebuild() || |
| 2445 | ElementType != T->getElementType()) { |
| 2446 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2447 | if (Result.isNull()) |
| 2448 | return QualType(); |
| 2449 | } |
| 2450 | |
| 2451 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2452 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2453 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2454 | return Result; |
| 2455 | } |
| 2456 | |
| 2457 | template<typename Derived> |
| 2458 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2459 | ExtVectorTypeLoc TL) { |
| 2460 | VectorType *T = TL.getTypePtr(); |
| 2461 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2462 | if (ElementType.isNull()) |
| 2463 | return QualType(); |
| 2464 | |
| 2465 | QualType Result = TL.getType(); |
| 2466 | if (getDerived().AlwaysRebuild() || |
| 2467 | ElementType != T->getElementType()) { |
| 2468 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2469 | T->getNumElements(), |
| 2470 | /*FIXME*/ SourceLocation()); |
| 2471 | if (Result.isNull()) |
| 2472 | return QualType(); |
| 2473 | } |
| 2474 | |
| 2475 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2476 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2477 | |
| 2478 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2479 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2480 | |
| 2481 | template<typename Derived> |
| 2482 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2483 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2484 | FunctionProtoTypeLoc TL) { |
| 2485 | FunctionProtoType *T = TL.getTypePtr(); |
| 2486 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2487 | if (ResultType.isNull()) |
| 2488 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2489 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2490 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2491 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2492 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2493 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2494 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2495 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2496 | QualType NewType; |
| 2497 | ParmVarDecl *NewParm; |
| 2498 | |
| 2499 | if (OldParm) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2500 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2501 | assert(OldDI->getType() == T->getArgType(i)); |
| 2502 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2503 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2504 | if (!NewDI) |
| 2505 | return QualType(); |
| 2506 | |
| 2507 | if (NewDI == OldDI) |
| 2508 | NewParm = OldParm; |
| 2509 | else |
| 2510 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2511 | OldParm->getDeclContext(), |
| 2512 | OldParm->getLocation(), |
| 2513 | OldParm->getIdentifier(), |
| 2514 | NewDI->getType(), |
| 2515 | NewDI, |
| 2516 | OldParm->getStorageClass(), |
| 2517 | /* DefArg */ NULL); |
| 2518 | NewType = NewParm->getType(); |
| 2519 | |
| 2520 | // Deal with the possibility that we don't have a parameter |
| 2521 | // declaration for this parameter. |
| 2522 | } else { |
| 2523 | NewParm = 0; |
| 2524 | |
| 2525 | QualType OldType = T->getArgType(i); |
| 2526 | NewType = getDerived().TransformType(OldType); |
| 2527 | if (NewType.isNull()) |
| 2528 | return QualType(); |
| 2529 | } |
| 2530 | |
| 2531 | ParamTypes.push_back(NewType); |
| 2532 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2533 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2535 | QualType Result = TL.getType(); |
| 2536 | if (getDerived().AlwaysRebuild() || |
| 2537 | ResultType != T->getResultType() || |
| 2538 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2539 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2540 | ParamTypes.data(), |
| 2541 | ParamTypes.size(), |
| 2542 | T->isVariadic(), |
| 2543 | T->getTypeQuals()); |
| 2544 | if (Result.isNull()) |
| 2545 | return QualType(); |
| 2546 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2547 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2548 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2549 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2550 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2551 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2552 | NewTL.setArg(i, ParamDecls[i]); |
| 2553 | |
| 2554 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2555 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2556 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2557 | template<typename Derived> |
| 2558 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2559 | TypeLocBuilder &TLB, |
| 2560 | FunctionNoProtoTypeLoc TL) { |
| 2561 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2562 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2563 | if (ResultType.isNull()) |
| 2564 | return QualType(); |
| 2565 | |
| 2566 | QualType Result = TL.getType(); |
| 2567 | if (getDerived().AlwaysRebuild() || |
| 2568 | ResultType != T->getResultType()) |
| 2569 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2570 | |
| 2571 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2572 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2573 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2574 | |
| 2575 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2576 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2577 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2578 | template<typename Derived> QualType |
| 2579 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2580 | UnresolvedUsingTypeLoc TL) { |
| 2581 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2582 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2583 | if (!D) |
| 2584 | return QualType(); |
| 2585 | |
| 2586 | QualType Result = TL.getType(); |
| 2587 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2588 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2589 | if (Result.isNull()) |
| 2590 | return QualType(); |
| 2591 | } |
| 2592 | |
| 2593 | // We might get an arbitrary type spec type back. We should at |
| 2594 | // least always get a type spec type, though. |
| 2595 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2596 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2597 | |
| 2598 | return Result; |
| 2599 | } |
| 2600 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2601 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2602 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2603 | TypedefTypeLoc TL) { |
| 2604 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2605 | TypedefDecl *Typedef |
| 2606 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2607 | if (!Typedef) |
| 2608 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2609 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2610 | QualType Result = TL.getType(); |
| 2611 | if (getDerived().AlwaysRebuild() || |
| 2612 | Typedef != T->getDecl()) { |
| 2613 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2614 | if (Result.isNull()) |
| 2615 | return QualType(); |
| 2616 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2617 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2618 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2619 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2620 | |
| 2621 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2624 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2625 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2626 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2627 | // typeof expressions are not potentially evaluated contexts |
| 2628 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2629 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2630 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2631 | if (E.isInvalid()) |
| 2632 | return QualType(); |
| 2633 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2634 | QualType Result = TL.getType(); |
| 2635 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2636 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2637 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2638 | if (Result.isNull()) |
| 2639 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2640 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2641 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2642 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2643 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2644 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2645 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2646 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2647 | |
| 2648 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2650 | |
| 2651 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2652 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2653 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2654 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2655 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2656 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2657 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2658 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2659 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2660 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2661 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2662 | if (Result.isNull()) |
| 2663 | return QualType(); |
| 2664 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2665 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2666 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2667 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2668 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2669 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2670 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2671 | |
| 2672 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2674 | |
| 2675 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2676 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2677 | DecltypeTypeLoc TL) { |
| 2678 | DecltypeType *T = TL.getTypePtr(); |
| 2679 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2680 | // decltype expressions are not potentially evaluated contexts |
| 2681 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2682 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2683 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2684 | if (E.isInvalid()) |
| 2685 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2686 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2687 | QualType Result = TL.getType(); |
| 2688 | if (getDerived().AlwaysRebuild() || |
| 2689 | E.get() != T->getUnderlyingExpr()) { |
| 2690 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2691 | if (Result.isNull()) |
| 2692 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2693 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2694 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2695 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2696 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2697 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2698 | |
| 2699 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2703 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2704 | RecordTypeLoc TL) { |
| 2705 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2706 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2707 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2708 | if (!Record) |
| 2709 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2710 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2711 | QualType Result = TL.getType(); |
| 2712 | if (getDerived().AlwaysRebuild() || |
| 2713 | Record != T->getDecl()) { |
| 2714 | Result = getDerived().RebuildRecordType(Record); |
| 2715 | if (Result.isNull()) |
| 2716 | return QualType(); |
| 2717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2718 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2719 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2720 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2721 | |
| 2722 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2724 | |
| 2725 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2727 | EnumTypeLoc TL) { |
| 2728 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2729 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2730 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2731 | if (!Enum) |
| 2732 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2733 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2734 | QualType Result = TL.getType(); |
| 2735 | if (getDerived().AlwaysRebuild() || |
| 2736 | Enum != T->getDecl()) { |
| 2737 | Result = getDerived().RebuildEnumType(Enum); |
| 2738 | if (Result.isNull()) |
| 2739 | return QualType(); |
| 2740 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2742 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2743 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2744 | |
| 2745 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2746 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2747 | |
| 2748 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2749 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2750 | ElaboratedTypeLoc TL) { |
| 2751 | ElaboratedType *T = TL.getTypePtr(); |
| 2752 | |
| 2753 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2754 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2755 | if (Underlying.isNull()) |
| 2756 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2757 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2758 | QualType Result = TL.getType(); |
| 2759 | if (getDerived().AlwaysRebuild() || |
| 2760 | Underlying != T->getUnderlyingType()) { |
| 2761 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2762 | if (Result.isNull()) |
| 2763 | return QualType(); |
| 2764 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2766 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2767 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2768 | |
| 2769 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2770 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2771 | |
| 2772 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2773 | template<typename Derived> |
| 2774 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2775 | TypeLocBuilder &TLB, |
| 2776 | TemplateTypeParmTypeLoc TL) { |
| 2777 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2780 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2781 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2782 | TypeLocBuilder &TLB, |
| 2783 | SubstTemplateTypeParmTypeLoc TL) { |
| 2784 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2788 | inline QualType |
| 2789 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2790 | TypeLocBuilder &TLB, |
| 2791 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2792 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2793 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2794 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2795 | template<typename Derived> |
| 2796 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2797 | const TemplateSpecializationType *TST, |
| 2798 | QualType ObjectType) { |
| 2799 | // FIXME: this entire method is a temporary workaround; callers |
| 2800 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2801 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2802 | // Fake up a TemplateSpecializationTypeLoc. |
| 2803 | TypeLocBuilder TLB; |
| 2804 | TemplateSpecializationTypeLoc TL |
| 2805 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2806 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2807 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2808 | |
| 2809 | TL.setTemplateNameLoc(BaseLoc); |
| 2810 | TL.setLAngleLoc(BaseLoc); |
| 2811 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2812 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2813 | const TemplateArgument &TA = TST->getArg(i); |
| 2814 | TemplateArgumentLoc TAL; |
| 2815 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2816 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2817 | } |
| 2818 | |
| 2819 | TypeLocBuilder IgnoredTLB; |
| 2820 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2824 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2825 | TypeLocBuilder &TLB, |
| 2826 | TemplateSpecializationTypeLoc TL, |
| 2827 | QualType ObjectType) { |
| 2828 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2829 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2830 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2831 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2832 | if (Template.isNull()) |
| 2833 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2834 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2835 | TemplateArgumentListInfo NewTemplateArgs; |
| 2836 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2837 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2838 | |
| 2839 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2840 | TemplateArgumentLoc Loc; |
| 2841 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2842 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2843 | NewTemplateArgs.addArgument(Loc); |
| 2844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2845 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2846 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2847 | |
| 2848 | QualType Result = |
| 2849 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2850 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2851 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2852 | |
| 2853 | if (!Result.isNull()) { |
| 2854 | TemplateSpecializationTypeLoc NewTL |
| 2855 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2856 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2857 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2858 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2859 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2860 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2861 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2862 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2863 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2864 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2865 | |
| 2866 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2867 | QualType |
| 2868 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2869 | QualifiedNameTypeLoc TL) { |
| 2870 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2871 | NestedNameSpecifier *NNS |
| 2872 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2873 | SourceRange()); |
| 2874 | if (!NNS) |
| 2875 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2876 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2877 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2878 | if (Named.isNull()) |
| 2879 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2880 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2881 | QualType Result = TL.getType(); |
| 2882 | if (getDerived().AlwaysRebuild() || |
| 2883 | NNS != T->getQualifier() || |
| 2884 | Named != T->getNamedType()) { |
| 2885 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2886 | if (Result.isNull()) |
| 2887 | return QualType(); |
| 2888 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2889 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2890 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2891 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2892 | |
| 2893 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2894 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2895 | |
| 2896 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2897 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2898 | TypenameTypeLoc TL) { |
| 2899 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2900 | |
| 2901 | /* FIXME: preserve source information better than this */ |
| 2902 | SourceRange SR(TL.getNameLoc()); |
| 2903 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2904 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2905 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2906 | if (!NNS) |
| 2907 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2908 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2909 | QualType Result; |
| 2910 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2911 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2912 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2913 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2914 | if (NewTemplateId.isNull()) |
| 2915 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2916 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2917 | if (!getDerived().AlwaysRebuild() && |
| 2918 | NNS == T->getQualifier() && |
| 2919 | NewTemplateId == QualType(TemplateId, 0)) |
| 2920 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2922 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2923 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2924 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2925 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2926 | if (Result.isNull()) |
| 2927 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2928 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2929 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2930 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2931 | |
| 2932 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2933 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2935 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2936 | QualType |
| 2937 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2938 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2939 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2940 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2941 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2942 | |
| 2943 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2944 | QualType |
| 2945 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2946 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2947 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2948 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2949 | } |
| 2950 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2951 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2952 | // Statement transformation |
| 2953 | //===----------------------------------------------------------------------===// |
| 2954 | template<typename Derived> |
| 2955 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2956 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2957 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | template<typename Derived> |
| 2961 | Sema::OwningStmtResult |
| 2962 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2963 | return getDerived().TransformCompoundStmt(S, false); |
| 2964 | } |
| 2965 | |
| 2966 | template<typename Derived> |
| 2967 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2969 | bool IsStmtExpr) { |
| 2970 | bool SubStmtChanged = false; |
| 2971 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2972 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2973 | B != BEnd; ++B) { |
| 2974 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2975 | if (Result.isInvalid()) |
| 2976 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2977 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2978 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2979 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2980 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2981 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2982 | if (!getDerived().AlwaysRebuild() && |
| 2983 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2984 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2985 | |
| 2986 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2987 | move_arg(Statements), |
| 2988 | S->getRBracLoc(), |
| 2989 | IsStmtExpr); |
| 2990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2991 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2992 | template<typename Derived> |
| 2993 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 2995 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 2996 | { |
| 2997 | // The case value expressions are not potentially evaluated. |
| 2998 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2999 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3000 | // Transform the left-hand case value. |
| 3001 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3002 | if (LHS.isInvalid()) |
| 3003 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3005 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3006 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3007 | if (RHS.isInvalid()) |
| 3008 | return SemaRef.StmtError(); |
| 3009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3010 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3011 | // Build the case statement. |
| 3012 | // Case statements are always rebuilt so that they will attached to their |
| 3013 | // transformed switch statement. |
| 3014 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3015 | move(LHS), |
| 3016 | S->getEllipsisLoc(), |
| 3017 | move(RHS), |
| 3018 | S->getColonLoc()); |
| 3019 | if (Case.isInvalid()) |
| 3020 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3021 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3022 | // Transform the statement following the case |
| 3023 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3024 | if (SubStmt.isInvalid()) |
| 3025 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3027 | // Attach the body to the case statement |
| 3028 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3029 | } |
| 3030 | |
| 3031 | template<typename Derived> |
| 3032 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3033 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3034 | // Transform the statement following the default case |
| 3035 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3036 | if (SubStmt.isInvalid()) |
| 3037 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3038 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3039 | // Default statements are always rebuilt |
| 3040 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3041 | move(SubStmt)); |
| 3042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3043 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3044 | template<typename Derived> |
| 3045 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3047 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3048 | if (SubStmt.isInvalid()) |
| 3049 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3050 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3051 | // FIXME: Pass the real colon location in. |
| 3052 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3053 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3054 | move(SubStmt)); |
| 3055 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3056 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3057 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3058 | Sema::OwningStmtResult |
| 3059 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3060 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3061 | OwningExprResult Cond(SemaRef); |
| 3062 | VarDecl *ConditionVar = 0; |
| 3063 | if (S->getConditionVariable()) { |
| 3064 | ConditionVar |
| 3065 | = cast_or_null<VarDecl>( |
| 3066 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3067 | if (!ConditionVar) |
| 3068 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3069 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3070 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3071 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3072 | if (Cond.isInvalid()) |
| 3073 | return SemaRef.StmtError(); |
| 3074 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3075 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3076 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3078 | // Transform the "then" branch. |
| 3079 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3080 | if (Then.isInvalid()) |
| 3081 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3082 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3083 | // Transform the "else" branch. |
| 3084 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3085 | if (Else.isInvalid()) |
| 3086 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3088 | if (!getDerived().AlwaysRebuild() && |
| 3089 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3090 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3091 | Then.get() == S->getThen() && |
| 3092 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | return SemaRef.Owned(S->Retain()); |
| 3094 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3095 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3096 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3097 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | template<typename Derived> |
| 3101 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3102 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3103 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3104 | OwningExprResult Cond(SemaRef); |
| 3105 | VarDecl *ConditionVar = 0; |
| 3106 | if (S->getConditionVariable()) { |
| 3107 | ConditionVar |
| 3108 | = cast_or_null<VarDecl>( |
| 3109 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3110 | if (!ConditionVar) |
| 3111 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3112 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3113 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3114 | |
| 3115 | if (Cond.isInvalid()) |
| 3116 | return SemaRef.StmtError(); |
| 3117 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3118 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3119 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3120 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3121 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3122 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3123 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3124 | if (Switch.isInvalid()) |
| 3125 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3126 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3127 | // Transform the body of the switch statement. |
| 3128 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3129 | if (Body.isInvalid()) |
| 3130 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3131 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3132 | // Complete the switch statement. |
| 3133 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3134 | move(Body)); |
| 3135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3136 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3137 | template<typename Derived> |
| 3138 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3139 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3140 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3141 | OwningExprResult Cond(SemaRef); |
| 3142 | VarDecl *ConditionVar = 0; |
| 3143 | if (S->getConditionVariable()) { |
| 3144 | ConditionVar |
| 3145 | = cast_or_null<VarDecl>( |
| 3146 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3147 | if (!ConditionVar) |
| 3148 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3149 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3150 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3151 | |
| 3152 | if (Cond.isInvalid()) |
| 3153 | return SemaRef.StmtError(); |
| 3154 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3155 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3156 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3157 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3158 | // Transform the body |
| 3159 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3160 | if (Body.isInvalid()) |
| 3161 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | if (!getDerived().AlwaysRebuild() && |
| 3164 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3165 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3166 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | return SemaRef.Owned(S->Retain()); |
| 3168 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3169 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3170 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3171 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3172 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3173 | template<typename Derived> |
| 3174 | Sema::OwningStmtResult |
| 3175 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3176 | // Transform the condition |
| 3177 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3178 | if (Cond.isInvalid()) |
| 3179 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3180 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3181 | // Transform the body |
| 3182 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3183 | if (Body.isInvalid()) |
| 3184 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3185 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3186 | if (!getDerived().AlwaysRebuild() && |
| 3187 | Cond.get() == S->getCond() && |
| 3188 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | return SemaRef.Owned(S->Retain()); |
| 3190 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3191 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3192 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3193 | S->getRParenLoc()); |
| 3194 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3195 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3196 | template<typename Derived> |
| 3197 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3199 | // Transform the initialization statement |
| 3200 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3201 | if (Init.isInvalid()) |
| 3202 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3205 | OwningExprResult Cond(SemaRef); |
| 3206 | VarDecl *ConditionVar = 0; |
| 3207 | if (S->getConditionVariable()) { |
| 3208 | ConditionVar |
| 3209 | = cast_or_null<VarDecl>( |
| 3210 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3211 | if (!ConditionVar) |
| 3212 | return SemaRef.StmtError(); |
| 3213 | } else { |
| 3214 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3215 | |
| 3216 | if (Cond.isInvalid()) |
| 3217 | return SemaRef.StmtError(); |
| 3218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3219 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3220 | // Transform the increment |
| 3221 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3222 | if (Inc.isInvalid()) |
| 3223 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3224 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3225 | // Transform the body |
| 3226 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3227 | if (Body.isInvalid()) |
| 3228 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3230 | if (!getDerived().AlwaysRebuild() && |
| 3231 | Init.get() == S->getInit() && |
| 3232 | Cond.get() == S->getCond() && |
| 3233 | Inc.get() == S->getInc() && |
| 3234 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3235 | return SemaRef.Owned(S->Retain()); |
| 3236 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3237 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3238 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3239 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3240 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3241 | S->getRParenLoc(), move(Body)); |
| 3242 | } |
| 3243 | |
| 3244 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3245 | Sema::OwningStmtResult |
| 3246 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3247 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3248 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3249 | S->getLabel()); |
| 3250 | } |
| 3251 | |
| 3252 | template<typename Derived> |
| 3253 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3255 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3256 | if (Target.isInvalid()) |
| 3257 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3258 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3259 | if (!getDerived().AlwaysRebuild() && |
| 3260 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3262 | |
| 3263 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3264 | move(Target)); |
| 3265 | } |
| 3266 | |
| 3267 | template<typename Derived> |
| 3268 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3269 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3270 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3272 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3273 | template<typename Derived> |
| 3274 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3276 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3277 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3279 | template<typename Derived> |
| 3280 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3283 | if (Result.isInvalid()) |
| 3284 | return SemaRef.StmtError(); |
| 3285 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | // to tell whether the return type of the function has changed. |
| 3288 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3291 | template<typename Derived> |
| 3292 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3293 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3294 | bool DeclChanged = false; |
| 3295 | llvm::SmallVector<Decl *, 4> Decls; |
| 3296 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3297 | D != DEnd; ++D) { |
| 3298 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3299 | if (!Transformed) |
| 3300 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3301 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3302 | if (Transformed != *D) |
| 3303 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3305 | Decls.push_back(Transformed); |
| 3306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3308 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | return SemaRef.Owned(S->Retain()); |
| 3310 | |
| 3311 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3312 | S->getStartLoc(), S->getEndLoc()); |
| 3313 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3314 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3315 | template<typename Derived> |
| 3316 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3318 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | template<typename Derived> |
| 3323 | Sema::OwningStmtResult |
| 3324 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3325 | // FIXME: Implement! |
| 3326 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3327 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | |
| 3331 | template<typename Derived> |
| 3332 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3334 | // FIXME: Implement this |
| 3335 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | template<typename Derived> |
| 3340 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | // FIXME: Implement this |
| 3343 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3344 | return SemaRef.Owned(S->Retain()); |
| 3345 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3347 | template<typename Derived> |
| 3348 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3349 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | // FIXME: Implement this |
| 3351 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3354 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3355 | template<typename Derived> |
| 3356 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3358 | // FIXME: Implement this |
| 3359 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3360 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | template<typename Derived> |
| 3364 | Sema::OwningStmtResult |
| 3365 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3366 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3367 | // FIXME: Implement this |
| 3368 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3369 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | template<typename Derived> |
| 3373 | Sema::OwningStmtResult |
| 3374 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3375 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3376 | // FIXME: Implement this |
| 3377 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3378 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | |
| 3382 | template<typename Derived> |
| 3383 | Sema::OwningStmtResult |
| 3384 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3385 | // Transform the exception declaration, if any. |
| 3386 | VarDecl *Var = 0; |
| 3387 | if (S->getExceptionDecl()) { |
| 3388 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3389 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3390 | ExceptionDecl->getDeclName()); |
| 3391 | |
| 3392 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3393 | if (T.isNull()) |
| 3394 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3396 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3397 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3398 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3399 | ExceptionDecl->getIdentifier(), |
| 3400 | ExceptionDecl->getLocation(), |
| 3401 | /*FIXME: Inaccurate*/ |
| 3402 | SourceRange(ExceptionDecl->getLocation())); |
| 3403 | if (!Var || Var->isInvalidDecl()) { |
| 3404 | if (Var) |
| 3405 | Var->Destroy(SemaRef.Context); |
| 3406 | return SemaRef.StmtError(); |
| 3407 | } |
| 3408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3410 | // Transform the actual exception handler. |
| 3411 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3412 | if (Handler.isInvalid()) { |
| 3413 | if (Var) |
| 3414 | Var->Destroy(SemaRef.Context); |
| 3415 | return SemaRef.StmtError(); |
| 3416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3418 | if (!getDerived().AlwaysRebuild() && |
| 3419 | !Var && |
| 3420 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3421 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3422 | |
| 3423 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3424 | Var, |
| 3425 | move(Handler)); |
| 3426 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3428 | template<typename Derived> |
| 3429 | Sema::OwningStmtResult |
| 3430 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3431 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3434 | if (TryBlock.isInvalid()) |
| 3435 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3436 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3437 | // Transform the handlers. |
| 3438 | bool HandlerChanged = false; |
| 3439 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3440 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3443 | if (Handler.isInvalid()) |
| 3444 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3446 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3447 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3448 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | if (!getDerived().AlwaysRebuild() && |
| 3451 | TryBlock.get() == S->getTryBlock() && |
| 3452 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3453 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3454 | |
| 3455 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3457 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3459 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3460 | // Expression transformation |
| 3461 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | template<typename Derived> |
| 3463 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3464 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3465 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3466 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3467 | |
| 3468 | template<typename Derived> |
| 3469 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3470 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3471 | NestedNameSpecifier *Qualifier = 0; |
| 3472 | if (E->getQualifier()) { |
| 3473 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3474 | E->getQualifierRange()); |
| 3475 | if (!Qualifier) |
| 3476 | return SemaRef.ExprError(); |
| 3477 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3478 | |
| 3479 | ValueDecl *ND |
| 3480 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3481 | if (!ND) |
| 3482 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3483 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3484 | if (!getDerived().AlwaysRebuild() && |
| 3485 | Qualifier == E->getQualifier() && |
| 3486 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3487 | !E->hasExplicitTemplateArgumentList()) { |
| 3488 | |
| 3489 | // Mark it referenced in the new context regardless. |
| 3490 | // FIXME: this is a bit instantiation-specific. |
| 3491 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3492 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3493 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3494 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3495 | |
| 3496 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3497 | if (E->hasExplicitTemplateArgumentList()) { |
| 3498 | TemplateArgs = &TransArgs; |
| 3499 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3500 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3501 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3502 | TemplateArgumentLoc Loc; |
| 3503 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3504 | return SemaRef.ExprError(); |
| 3505 | TransArgs.addArgument(Loc); |
| 3506 | } |
| 3507 | } |
| 3508 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3509 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3510 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3512 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3513 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3515 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3517 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3519 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3520 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3521 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3522 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3524 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3525 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3527 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3531 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3533 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3534 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3537 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3538 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3539 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | return SemaRef.Owned(E->Retain()); |
| 3541 | } |
| 3542 | |
| 3543 | template<typename Derived> |
| 3544 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3545 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3546 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3547 | if (SubExpr.isInvalid()) |
| 3548 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3550 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3551 | return SemaRef.Owned(E->Retain()); |
| 3552 | |
| 3553 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3554 | E->getRParen()); |
| 3555 | } |
| 3556 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3557 | template<typename Derived> |
| 3558 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3559 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3560 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3561 | if (SubExpr.isInvalid()) |
| 3562 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3564 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | return SemaRef.Owned(E->Retain()); |
| 3566 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3567 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3568 | E->getOpcode(), |
| 3569 | move(SubExpr)); |
| 3570 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3572 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3574 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3575 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3576 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3577 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3578 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3579 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3580 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3581 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3582 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3583 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3584 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3585 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3587 | E->getSourceRange()); |
| 3588 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3590 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3591 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3592 | // C++0x [expr.sizeof]p1: |
| 3593 | // The operand is either an expression, which is an unevaluated operand |
| 3594 | // [...] |
| 3595 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3596 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3597 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3598 | if (SubExpr.isInvalid()) |
| 3599 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3600 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3601 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3602 | return SemaRef.Owned(E->Retain()); |
| 3603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3605 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3606 | E->isSizeOf(), |
| 3607 | E->getSourceRange()); |
| 3608 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3609 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3610 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3611 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3612 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3613 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3614 | if (LHS.isInvalid()) |
| 3615 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3617 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3618 | if (RHS.isInvalid()) |
| 3619 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | |
| 3621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3622 | if (!getDerived().AlwaysRebuild() && |
| 3623 | LHS.get() == E->getLHS() && |
| 3624 | RHS.get() == E->getRHS()) |
| 3625 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3627 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3628 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3629 | move(RHS), |
| 3630 | E->getRBracketLoc()); |
| 3631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
| 3633 | template<typename Derived> |
| 3634 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3635 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3636 | // Transform the callee. |
| 3637 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3638 | if (Callee.isInvalid()) |
| 3639 | return SemaRef.ExprError(); |
| 3640 | |
| 3641 | // Transform arguments. |
| 3642 | bool ArgChanged = false; |
| 3643 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3644 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3645 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3646 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3647 | if (Arg.isInvalid()) |
| 3648 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3650 | // FIXME: Wrong source location information for the ','. |
| 3651 | FakeCommaLocs.push_back( |
| 3652 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
| 3654 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3655 | Args.push_back(Arg.takeAs<Expr>()); |
| 3656 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3658 | if (!getDerived().AlwaysRebuild() && |
| 3659 | Callee.get() == E->getCallee() && |
| 3660 | !ArgChanged) |
| 3661 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3663 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3664 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3665 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3666 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3667 | move_arg(Args), |
| 3668 | FakeCommaLocs.data(), |
| 3669 | E->getRParenLoc()); |
| 3670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3671 | |
| 3672 | template<typename Derived> |
| 3673 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3674 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3676 | if (Base.isInvalid()) |
| 3677 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3679 | NestedNameSpecifier *Qualifier = 0; |
| 3680 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3681 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3682 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3683 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3684 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3685 | return SemaRef.ExprError(); |
| 3686 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3687 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3688 | ValueDecl *Member |
| 3689 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3690 | if (!Member) |
| 3691 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3693 | if (!getDerived().AlwaysRebuild() && |
| 3694 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3695 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3696 | Member == E->getMemberDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3697 | !E->hasExplicitTemplateArgumentList()) { |
| 3698 | |
| 3699 | // Mark it referenced in the new context regardless. |
| 3700 | // FIXME: this is a bit instantiation-specific. |
| 3701 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3703 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3704 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3705 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3706 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3707 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3708 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3709 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3710 | TemplateArgumentLoc Loc; |
| 3711 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3712 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3713 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3714 | } |
| 3715 | } |
| 3716 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3717 | // FIXME: Bogus source location for the operator |
| 3718 | SourceLocation FakeOperatorLoc |
| 3719 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3720 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 3721 | // FIXME: to do this check properly, we will need to preserve the |
| 3722 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3723 | // base (and therefore couldn't do the check) and a |
| 3724 | // nested-name-qualifier (and therefore could do the lookup). |
| 3725 | NamedDecl *FirstQualifierInScope = 0; |
| 3726 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3728 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3729 | Qualifier, |
| 3730 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3731 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3732 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3733 | (E->hasExplicitTemplateArgumentList() |
| 3734 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 3735 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3736 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3737 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3738 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3739 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3740 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3741 | assert(false && "Cannot transform abstract class"); |
| 3742 | return SemaRef.Owned(E->Retain()); |
| 3743 | } |
| 3744 | |
| 3745 | template<typename Derived> |
| 3746 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3747 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3749 | if (LHS.isInvalid()) |
| 3750 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3751 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3752 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3753 | if (RHS.isInvalid()) |
| 3754 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3756 | if (!getDerived().AlwaysRebuild() && |
| 3757 | LHS.get() == E->getLHS() && |
| 3758 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3759 | return SemaRef.Owned(E->Retain()); |
| 3760 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3761 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3762 | move(LHS), move(RHS)); |
| 3763 | } |
| 3764 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3765 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3766 | Sema::OwningExprResult |
| 3767 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3768 | CompoundAssignOperator *E) { |
| 3769 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3770 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3771 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3772 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3774 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3775 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3776 | if (Cond.isInvalid()) |
| 3777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3779 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3780 | if (LHS.isInvalid()) |
| 3781 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3783 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3784 | if (RHS.isInvalid()) |
| 3785 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3787 | if (!getDerived().AlwaysRebuild() && |
| 3788 | Cond.get() == E->getCond() && |
| 3789 | LHS.get() == E->getLHS() && |
| 3790 | RHS.get() == E->getRHS()) |
| 3791 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
| 3793 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3794 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3796 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3797 | move(RHS)); |
| 3798 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
| 3800 | template<typename Derived> |
| 3801 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3802 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3803 | // Implicit casts are eliminated during transformation, since they |
| 3804 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3805 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3807 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3808 | template<typename Derived> |
| 3809 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3810 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | assert(false && "Cannot transform abstract class"); |
| 3812 | return SemaRef.Owned(E->Retain()); |
| 3813 | } |
| 3814 | |
| 3815 | template<typename Derived> |
| 3816 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3817 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3818 | QualType T; |
| 3819 | { |
| 3820 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3821 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3822 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3823 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3824 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3825 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3826 | if (T.isNull()) |
| 3827 | return SemaRef.ExprError(); |
| 3828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3830 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3831 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3832 | if (SubExpr.isInvalid()) |
| 3833 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3834 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3835 | if (!getDerived().AlwaysRebuild() && |
| 3836 | T == E->getTypeAsWritten() && |
| 3837 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3838 | return SemaRef.Owned(E->Retain()); |
| 3839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3840 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3841 | E->getRParenLoc(), |
| 3842 | move(SubExpr)); |
| 3843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3846 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3847 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3848 | QualType T; |
| 3849 | { |
| 3850 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3851 | SourceLocation FakeTypeLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3852 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3853 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3854 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3855 | T = getDerived().TransformType(E->getType()); |
| 3856 | if (T.isNull()) |
| 3857 | return SemaRef.ExprError(); |
| 3858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3859 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3860 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3861 | if (Init.isInvalid()) |
| 3862 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | if (!getDerived().AlwaysRebuild() && |
| 3865 | T == E->getType() && |
| 3866 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | |
| 3869 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3870 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3871 | move(Init)); |
| 3872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3874 | template<typename Derived> |
| 3875 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3876 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3877 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3878 | if (Base.isInvalid()) |
| 3879 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3880 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3881 | if (!getDerived().AlwaysRebuild() && |
| 3882 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | return SemaRef.Owned(E->Retain()); |
| 3884 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3885 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3886 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3887 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3888 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3889 | E->getAccessorLoc(), |
| 3890 | E->getAccessor()); |
| 3891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3892 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3893 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3894 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3895 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3896 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3899 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3900 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3901 | if (Init.isInvalid()) |
| 3902 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3904 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3905 | Inits.push_back(Init.takeAs<Expr>()); |
| 3906 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3908 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3909 | return SemaRef.Owned(E->Retain()); |
| 3910 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3911 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3912 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3914 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | template<typename Derived> |
| 3916 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3917 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3918 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3920 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3922 | if (Init.isInvalid()) |
| 3923 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3924 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3925 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3926 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3927 | bool ExprChanged = false; |
| 3928 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3929 | DEnd = E->designators_end(); |
| 3930 | D != DEnd; ++D) { |
| 3931 | if (D->isFieldDesignator()) { |
| 3932 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3933 | D->getDotLoc(), |
| 3934 | D->getFieldLoc())); |
| 3935 | continue; |
| 3936 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3938 | if (D->isArrayDesignator()) { |
| 3939 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3940 | if (Index.isInvalid()) |
| 3941 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | |
| 3943 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3946 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3947 | ArrayExprs.push_back(Index.release()); |
| 3948 | continue; |
| 3949 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3951 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3953 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3954 | if (Start.isInvalid()) |
| 3955 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3957 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3958 | if (End.isInvalid()) |
| 3959 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
| 3961 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3962 | End.get(), |
| 3963 | D->getLBracketLoc(), |
| 3964 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3966 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3967 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3969 | ArrayExprs.push_back(Start.release()); |
| 3970 | ArrayExprs.push_back(End.release()); |
| 3971 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | if (!getDerived().AlwaysRebuild() && |
| 3974 | Init.get() == E->getInit() && |
| 3975 | !ExprChanged) |
| 3976 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3977 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3978 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3979 | E->getEqualOrColonLoc(), |
| 3980 | E->usesGNUSyntax(), move(Init)); |
| 3981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3982 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3983 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3984 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3985 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3986 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3987 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3988 | |
| 3989 | // FIXME: Will we ever have proper type location here? Will we actually |
| 3990 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3991 | QualType T = getDerived().TransformType(E->getType()); |
| 3992 | if (T.isNull()) |
| 3993 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3994 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | if (!getDerived().AlwaysRebuild() && |
| 3996 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | return SemaRef.Owned(E->Retain()); |
| 3998 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4000 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4002 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4003 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4004 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4005 | // FIXME: Do we want the type as written? |
| 4006 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4008 | { |
| 4009 | // FIXME: Source location isn't quite accurate. |
| 4010 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4011 | T = getDerived().TransformType(E->getType()); |
| 4012 | if (T.isNull()) |
| 4013 | return SemaRef.ExprError(); |
| 4014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4016 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4017 | if (SubExpr.isInvalid()) |
| 4018 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4020 | if (!getDerived().AlwaysRebuild() && |
| 4021 | T == E->getType() && |
| 4022 | SubExpr.get() == E->getSubExpr()) |
| 4023 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4024 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4025 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4026 | T, E->getRParenLoc()); |
| 4027 | } |
| 4028 | |
| 4029 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4030 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4031 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4032 | bool ArgumentChanged = false; |
| 4033 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4034 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4035 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4036 | if (Init.isInvalid()) |
| 4037 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4039 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4040 | Inits.push_back(Init.takeAs<Expr>()); |
| 4041 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4043 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4044 | move_arg(Inits), |
| 4045 | E->getRParenLoc()); |
| 4046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | /// \brief Transform an address-of-label expression. |
| 4049 | /// |
| 4050 | /// By default, the transformation of an address-of-label expression always |
| 4051 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4052 | /// the corresponding label statement by semantic analysis. |
| 4053 | template<typename Derived> |
| 4054 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4055 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4056 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4057 | E->getLabel()); |
| 4058 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | |
| 4060 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4061 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4062 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4065 | if (SubStmt.isInvalid()) |
| 4066 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4067 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4068 | if (!getDerived().AlwaysRebuild() && |
| 4069 | SubStmt.get() == E->getSubStmt()) |
| 4070 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4071 | |
| 4072 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4073 | move(SubStmt), |
| 4074 | E->getRParenLoc()); |
| 4075 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | template<typename Derived> |
| 4078 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4079 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4080 | QualType T1, T2; |
| 4081 | { |
| 4082 | // FIXME: Source location isn't quite accurate. |
| 4083 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4085 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4086 | if (T1.isNull()) |
| 4087 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4088 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4089 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4090 | if (T2.isNull()) |
| 4091 | return SemaRef.ExprError(); |
| 4092 | } |
| 4093 | |
| 4094 | if (!getDerived().AlwaysRebuild() && |
| 4095 | T1 == E->getArgType1() && |
| 4096 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4097 | return SemaRef.Owned(E->Retain()); |
| 4098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4099 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4100 | T1, T2, E->getRParenLoc()); |
| 4101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4102 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4103 | template<typename Derived> |
| 4104 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4105 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4106 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4107 | if (Cond.isInvalid()) |
| 4108 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4111 | if (LHS.isInvalid()) |
| 4112 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4115 | if (RHS.isInvalid()) |
| 4116 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | if (!getDerived().AlwaysRebuild() && |
| 4119 | Cond.get() == E->getCond() && |
| 4120 | LHS.get() == E->getLHS() && |
| 4121 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4122 | return SemaRef.Owned(E->Retain()); |
| 4123 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4125 | move(Cond), move(LHS), move(RHS), |
| 4126 | E->getRParenLoc()); |
| 4127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4128 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4129 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4130 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4131 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | template<typename Derived> |
| 4136 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4137 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4138 | switch (E->getOperator()) { |
| 4139 | case OO_New: |
| 4140 | case OO_Delete: |
| 4141 | case OO_Array_New: |
| 4142 | case OO_Array_Delete: |
| 4143 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4144 | return SemaRef.ExprError(); |
| 4145 | |
| 4146 | case OO_Call: { |
| 4147 | // This is a call to an object's operator(). |
| 4148 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4149 | |
| 4150 | // Transform the object itself. |
| 4151 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4152 | if (Object.isInvalid()) |
| 4153 | return SemaRef.ExprError(); |
| 4154 | |
| 4155 | // FIXME: Poor location information |
| 4156 | SourceLocation FakeLParenLoc |
| 4157 | = SemaRef.PP.getLocForEndOfToken( |
| 4158 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4159 | |
| 4160 | // Transform the call arguments. |
| 4161 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4162 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4163 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4164 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4165 | break; |
| 4166 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4167 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4168 | if (Arg.isInvalid()) |
| 4169 | return SemaRef.ExprError(); |
| 4170 | |
| 4171 | // FIXME: Poor source location information. |
| 4172 | SourceLocation FakeCommaLoc |
| 4173 | = SemaRef.PP.getLocForEndOfToken( |
| 4174 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4175 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4176 | Args.push_back(Arg.release()); |
| 4177 | } |
| 4178 | |
| 4179 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4180 | move_arg(Args), |
| 4181 | FakeCommaLocs.data(), |
| 4182 | E->getLocEnd()); |
| 4183 | } |
| 4184 | |
| 4185 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4186 | case OO_##Name: |
| 4187 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4188 | #include "clang/Basic/OperatorKinds.def" |
| 4189 | case OO_Subscript: |
| 4190 | // Handled below. |
| 4191 | break; |
| 4192 | |
| 4193 | case OO_Conditional: |
| 4194 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4195 | return SemaRef.ExprError(); |
| 4196 | |
| 4197 | case OO_None: |
| 4198 | case NUM_OVERLOADED_OPERATORS: |
| 4199 | llvm_unreachable("not an overloaded operator?"); |
| 4200 | return SemaRef.ExprError(); |
| 4201 | } |
| 4202 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4203 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4204 | if (Callee.isInvalid()) |
| 4205 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4207 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4208 | if (First.isInvalid()) |
| 4209 | return SemaRef.ExprError(); |
| 4210 | |
| 4211 | OwningExprResult Second(SemaRef); |
| 4212 | if (E->getNumArgs() == 2) { |
| 4213 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4214 | if (Second.isInvalid()) |
| 4215 | return SemaRef.ExprError(); |
| 4216 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | if (!getDerived().AlwaysRebuild() && |
| 4219 | Callee.get() == E->getCallee() && |
| 4220 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4222 | return SemaRef.Owned(E->Retain()); |
| 4223 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4224 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4225 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | move(First), |
| 4228 | move(Second)); |
| 4229 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4231 | template<typename Derived> |
| 4232 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4233 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4234 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4239 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4240 | QualType ExplicitTy; |
| 4241 | { |
| 4242 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4244 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4245 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4248 | if (ExplicitTy.isNull()) |
| 4249 | return SemaRef.ExprError(); |
| 4250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4251 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4252 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4253 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | if (SubExpr.isInvalid()) |
| 4255 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4256 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4257 | if (!getDerived().AlwaysRebuild() && |
| 4258 | ExplicitTy == E->getTypeAsWritten() && |
| 4259 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4260 | return SemaRef.Owned(E->Retain()); |
| 4261 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4265 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4266 | SourceLocation FakeRParenLoc |
| 4267 | = SemaRef.PP.getLocForEndOfToken( |
| 4268 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4269 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4271 | FakeLAngleLoc, |
| 4272 | ExplicitTy, |
| 4273 | FakeRAngleLoc, |
| 4274 | FakeRAngleLoc, |
| 4275 | move(SubExpr), |
| 4276 | FakeRParenLoc); |
| 4277 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4278 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4279 | template<typename Derived> |
| 4280 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4281 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4282 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | |
| 4285 | template<typename Derived> |
| 4286 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4287 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4288 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4291 | template<typename Derived> |
| 4292 | Sema::OwningExprResult |
| 4293 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4294 | CXXReinterpretCastExpr *E) { |
| 4295 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4297 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4298 | template<typename Derived> |
| 4299 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4300 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4301 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | template<typename Derived> |
| 4305 | Sema::OwningExprResult |
| 4306 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4307 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4308 | QualType ExplicitTy; |
| 4309 | { |
| 4310 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4312 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4313 | if (ExplicitTy.isNull()) |
| 4314 | return SemaRef.ExprError(); |
| 4315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4317 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4318 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | if (SubExpr.isInvalid()) |
| 4320 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4321 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4322 | if (!getDerived().AlwaysRebuild() && |
| 4323 | ExplicitTy == E->getTypeAsWritten() && |
| 4324 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4325 | return SemaRef.Owned(E->Retain()); |
| 4326 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4327 | // FIXME: The end of the type's source range is wrong |
| 4328 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4329 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4330 | ExplicitTy, |
| 4331 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4332 | move(SubExpr), |
| 4333 | E->getRParenLoc()); |
| 4334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | template<typename Derived> |
| 4337 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4338 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | if (E->isTypeOperand()) { |
| 4340 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4342 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4343 | if (T.isNull()) |
| 4344 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4345 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4346 | if (!getDerived().AlwaysRebuild() && |
| 4347 | T == E->getTypeOperand()) |
| 4348 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4349 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4351 | /*FIXME:*/E->getLocStart(), |
| 4352 | T, |
| 4353 | E->getLocEnd()); |
| 4354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | // We don't know whether the expression is potentially evaluated until |
| 4357 | // after we perform semantic analysis, so the expression is potentially |
| 4358 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4359 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4360 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4361 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4363 | if (SubExpr.isInvalid()) |
| 4364 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4366 | if (!getDerived().AlwaysRebuild() && |
| 4367 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4368 | return SemaRef.Owned(E->Retain()); |
| 4369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4371 | /*FIXME:*/E->getLocStart(), |
| 4372 | move(SubExpr), |
| 4373 | E->getLocEnd()); |
| 4374 | } |
| 4375 | |
| 4376 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4378 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4379 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | template<typename Derived> |
| 4383 | Sema::OwningExprResult |
| 4384 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4385 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4386 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | template<typename Derived> |
| 4390 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4391 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | QualType T = getDerived().TransformType(E->getType()); |
| 4395 | if (T.isNull()) |
| 4396 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | if (!getDerived().AlwaysRebuild() && |
| 4399 | T == E->getType()) |
| 4400 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4402 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4403 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4405 | template<typename Derived> |
| 4406 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4407 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4409 | if (SubExpr.isInvalid()) |
| 4410 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | if (!getDerived().AlwaysRebuild() && |
| 4413 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4415 | |
| 4416 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4419 | template<typename Derived> |
| 4420 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4421 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4424 | if (!Param) |
| 4425 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | if (getDerived().AlwaysRebuild() && |
| 4428 | Param == E->getParam()) |
| 4429 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4431 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4434 | template<typename Derived> |
| 4435 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4436 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4438 | |
| 4439 | QualType T = getDerived().TransformType(E->getType()); |
| 4440 | if (T.isNull()) |
| 4441 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4442 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | if (!getDerived().AlwaysRebuild() && |
| 4444 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | return SemaRef.Owned(E->Retain()); |
| 4446 | |
| 4447 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4449 | T, |
| 4450 | E->getRParenLoc()); |
| 4451 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4453 | template<typename Derived> |
| 4454 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4455 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | // Transform the type that we're allocating |
| 4457 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4458 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4459 | if (AllocType.isNull()) |
| 4460 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4462 | // Transform the size of the array we're allocating (if any). |
| 4463 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4464 | if (ArraySize.isInvalid()) |
| 4465 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4467 | // Transform the placement arguments (if any). |
| 4468 | bool ArgumentChanged = false; |
| 4469 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4470 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4471 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4472 | if (Arg.isInvalid()) |
| 4473 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4476 | PlacementArgs.push_back(Arg.take()); |
| 4477 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4479 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4481 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4482 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4483 | if (Arg.isInvalid()) |
| 4484 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4486 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4487 | ConstructorArgs.push_back(Arg.take()); |
| 4488 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4489 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4490 | if (!getDerived().AlwaysRebuild() && |
| 4491 | AllocType == E->getAllocatedType() && |
| 4492 | ArraySize.get() == E->getArraySize() && |
| 4493 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | return SemaRef.Owned(E->Retain()); |
| 4495 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4496 | if (!ArraySize.get()) { |
| 4497 | // If no array size was specified, but the new expression was |
| 4498 | // instantiated with an array type (e.g., "new T" where T is |
| 4499 | // instantiated with "int[4]"), extract the outer bound from the |
| 4500 | // array type as our array size. We do this with constant and |
| 4501 | // dependently-sized array types. |
| 4502 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4503 | if (!ArrayT) { |
| 4504 | // Do nothing |
| 4505 | } else if (const ConstantArrayType *ConsArrayT |
| 4506 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4507 | ArraySize |
| 4508 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4509 | ConsArrayT->getSize(), |
| 4510 | SemaRef.Context.getSizeType(), |
| 4511 | /*FIXME:*/E->getLocStart())); |
| 4512 | AllocType = ConsArrayT->getElementType(); |
| 4513 | } else if (const DependentSizedArrayType *DepArrayT |
| 4514 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4515 | if (DepArrayT->getSizeExpr()) { |
| 4516 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4517 | AllocType = DepArrayT->getElementType(); |
| 4518 | } |
| 4519 | } |
| 4520 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4522 | E->isGlobalNew(), |
| 4523 | /*FIXME:*/E->getLocStart(), |
| 4524 | move_arg(PlacementArgs), |
| 4525 | /*FIXME:*/E->getLocStart(), |
| 4526 | E->isParenTypeId(), |
| 4527 | AllocType, |
| 4528 | /*FIXME:*/E->getLocStart(), |
| 4529 | /*FIXME:*/SourceRange(), |
| 4530 | move(ArraySize), |
| 4531 | /*FIXME:*/E->getLocStart(), |
| 4532 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4535 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4536 | template<typename Derived> |
| 4537 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4538 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4539 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4540 | if (Operand.isInvalid()) |
| 4541 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4544 | Operand.get() == E->getArgument()) |
| 4545 | return SemaRef.Owned(E->Retain()); |
| 4546 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4547 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4548 | E->isGlobalDelete(), |
| 4549 | E->isArrayForm(), |
| 4550 | move(Operand)); |
| 4551 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | template<typename Derived> |
| 4554 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4555 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4556 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4557 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4558 | if (Base.isInvalid()) |
| 4559 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4561 | NestedNameSpecifier *Qualifier |
| 4562 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4563 | E->getQualifierRange()); |
| 4564 | if (E->getQualifier() && !Qualifier) |
| 4565 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4567 | QualType DestroyedType; |
| 4568 | { |
| 4569 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4570 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4571 | if (DestroyedType.isNull()) |
| 4572 | return SemaRef.ExprError(); |
| 4573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4575 | if (!getDerived().AlwaysRebuild() && |
| 4576 | Base.get() == E->getBase() && |
| 4577 | Qualifier == E->getQualifier() && |
| 4578 | DestroyedType == E->getDestroyedType()) |
| 4579 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4581 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4582 | E->getOperatorLoc(), |
| 4583 | E->isArrow(), |
| 4584 | E->getDestroyedTypeLoc(), |
| 4585 | DestroyedType, |
| 4586 | Qualifier, |
| 4587 | E->getQualifierRange()); |
| 4588 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4589 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4590 | template<typename Derived> |
| 4591 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4592 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4593 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4594 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4595 | |
| 4596 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4597 | Sema::LookupOrdinaryName); |
| 4598 | |
| 4599 | // Transform all the decls. |
| 4600 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4601 | E = Old->decls_end(); I != E; ++I) { |
| 4602 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4603 | if (!InstD) { |
| 4604 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4605 | // This can happen because of dependent hiding. |
| 4606 | if (isa<UsingShadowDecl>(*I)) |
| 4607 | continue; |
| 4608 | else |
| 4609 | return SemaRef.ExprError(); |
| 4610 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4611 | |
| 4612 | // Expand using declarations. |
| 4613 | if (isa<UsingDecl>(InstD)) { |
| 4614 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4615 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4616 | E = UD->shadow_end(); I != E; ++I) |
| 4617 | R.addDecl(*I); |
| 4618 | continue; |
| 4619 | } |
| 4620 | |
| 4621 | R.addDecl(InstD); |
| 4622 | } |
| 4623 | |
| 4624 | // Resolve a kind, but don't do any further analysis. If it's |
| 4625 | // ambiguous, the callee needs to deal with it. |
| 4626 | R.resolveKind(); |
| 4627 | |
| 4628 | // Rebuild the nested-name qualifier, if present. |
| 4629 | CXXScopeSpec SS; |
| 4630 | NestedNameSpecifier *Qualifier = 0; |
| 4631 | if (Old->getQualifier()) { |
| 4632 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4633 | Old->getQualifierRange()); |
| 4634 | if (!Qualifier) |
| 4635 | return SemaRef.ExprError(); |
| 4636 | |
| 4637 | SS.setScopeRep(Qualifier); |
| 4638 | SS.setRange(Old->getQualifierRange()); |
| 4639 | } |
| 4640 | |
| 4641 | // If we have no template arguments, it's a normal declaration name. |
| 4642 | if (!Old->hasExplicitTemplateArgs()) |
| 4643 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4644 | |
| 4645 | // If we have template arguments, rebuild them, then rebuild the |
| 4646 | // templateid expression. |
| 4647 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4648 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4649 | TemplateArgumentLoc Loc; |
| 4650 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4651 | return SemaRef.ExprError(); |
| 4652 | TransArgs.addArgument(Loc); |
| 4653 | } |
| 4654 | |
| 4655 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4656 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | template<typename Derived> |
| 4660 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4661 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4662 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4665 | if (T.isNull()) |
| 4666 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | if (!getDerived().AlwaysRebuild() && |
| 4669 | T == E->getQueriedType()) |
| 4670 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4671 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4672 | // FIXME: Bad location information |
| 4673 | SourceLocation FakeLParenLoc |
| 4674 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
| 4676 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4677 | E->getLocStart(), |
| 4678 | /*FIXME:*/FakeLParenLoc, |
| 4679 | T, |
| 4680 | E->getLocEnd()); |
| 4681 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4682 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4683 | template<typename Derived> |
| 4684 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4685 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4686 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4687 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4688 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4689 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4690 | if (!NNS) |
| 4691 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4692 | |
| 4693 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4694 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4695 | if (!Name) |
| 4696 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4697 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4698 | if (!E->hasExplicitTemplateArgs()) { |
| 4699 | if (!getDerived().AlwaysRebuild() && |
| 4700 | NNS == E->getQualifier() && |
| 4701 | Name == E->getDeclName()) |
| 4702 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4703 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4704 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4705 | E->getQualifierRange(), |
| 4706 | Name, E->getLocation(), |
| 4707 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4708 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4709 | |
| 4710 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4711 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4712 | TemplateArgumentLoc Loc; |
| 4713 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4714 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4715 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4718 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4719 | E->getQualifierRange(), |
| 4720 | Name, E->getLocation(), |
| 4721 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | template<typename Derived> |
| 4725 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4726 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4727 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4728 | |
| 4729 | QualType T = getDerived().TransformType(E->getType()); |
| 4730 | if (T.isNull()) |
| 4731 | return SemaRef.ExprError(); |
| 4732 | |
| 4733 | CXXConstructorDecl *Constructor |
| 4734 | = cast_or_null<CXXConstructorDecl>( |
| 4735 | getDerived().TransformDecl(E->getConstructor())); |
| 4736 | if (!Constructor) |
| 4737 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4739 | bool ArgumentChanged = false; |
| 4740 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4741 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4742 | ArgEnd = E->arg_end(); |
| 4743 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4744 | if (getDerived().DropCallArgument(*Arg)) { |
| 4745 | ArgumentChanged = true; |
| 4746 | break; |
| 4747 | } |
| 4748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4749 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4750 | if (TransArg.isInvalid()) |
| 4751 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4752 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4753 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4754 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4755 | } |
| 4756 | |
| 4757 | if (!getDerived().AlwaysRebuild() && |
| 4758 | T == E->getType() && |
| 4759 | Constructor == E->getConstructor() && |
| 4760 | !ArgumentChanged) |
| 4761 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4762 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4763 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4764 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4765 | move_arg(Args)); |
| 4766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4768 | /// \brief Transform a C++ temporary-binding expression. |
| 4769 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4770 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4771 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4772 | template<typename Derived> |
| 4773 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4774 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4775 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | |
| 4778 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | /// be destroyed after the expression is evaluated. |
| 4780 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4781 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4782 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4783 | template<typename Derived> |
| 4784 | Sema::OwningExprResult |
| 4785 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4786 | CXXExprWithTemporaries *E) { |
| 4787 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4788 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4790 | template<typename Derived> |
| 4791 | Sema::OwningExprResult |
| 4792 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4793 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 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 | CXXConstructorDecl *Constructor |
| 4800 | = cast_or_null<CXXConstructorDecl>( |
| 4801 | getDerived().TransformDecl(E->getConstructor())); |
| 4802 | if (!Constructor) |
| 4803 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4805 | bool ArgumentChanged = false; |
| 4806 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4807 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4808 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4809 | ArgEnd = E->arg_end(); |
| 4810 | Arg != ArgEnd; ++Arg) { |
| 4811 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4812 | if (TransArg.isInvalid()) |
| 4813 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4814 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4815 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4816 | Args.push_back((Expr *)TransArg.release()); |
| 4817 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4819 | if (!getDerived().AlwaysRebuild() && |
| 4820 | T == E->getType() && |
| 4821 | Constructor == E->getConstructor() && |
| 4822 | !ArgumentChanged) |
| 4823 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4825 | // FIXME: Bogus location information |
| 4826 | SourceLocation CommaLoc; |
| 4827 | if (Args.size() > 1) { |
| 4828 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4831 | } |
| 4832 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4833 | T, |
| 4834 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4835 | move_arg(Args), |
| 4836 | &CommaLoc, |
| 4837 | E->getLocEnd()); |
| 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 | template<typename Derived> |
| 4841 | Sema::OwningExprResult |
| 4842 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4843 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4844 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4845 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4846 | if (T.isNull()) |
| 4847 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4848 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4849 | bool ArgumentChanged = false; |
| 4850 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4851 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4852 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4853 | ArgEnd = E->arg_end(); |
| 4854 | Arg != ArgEnd; ++Arg) { |
| 4855 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4856 | if (TransArg.isInvalid()) |
| 4857 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4859 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4860 | FakeCommaLocs.push_back( |
| 4861 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4862 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4863 | } |
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 | T == E->getTypeAsWritten() && |
| 4867 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4868 | return SemaRef.Owned(E->Retain()); |
| 4869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4870 | // FIXME: we're faking the locations of the commas |
| 4871 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4872 | T, |
| 4873 | E->getLParenLoc(), |
| 4874 | move_arg(Args), |
| 4875 | FakeCommaLocs.data(), |
| 4876 | E->getRParenLoc()); |
| 4877 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4878 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4879 | template<typename Derived> |
| 4880 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4881 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4882 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4883 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4884 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4885 | Expr *OldBase; |
| 4886 | QualType BaseType; |
| 4887 | QualType ObjectType; |
| 4888 | if (!E->isImplicitAccess()) { |
| 4889 | OldBase = E->getBase(); |
| 4890 | Base = getDerived().TransformExpr(OldBase); |
| 4891 | if (Base.isInvalid()) |
| 4892 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4893 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4894 | // Start the member reference and compute the object's type. |
| 4895 | Sema::TypeTy *ObjectTy = 0; |
| 4896 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4897 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4898 | E->isArrow()? tok::arrow : tok::period, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4899 | ObjectTy); |
| 4900 | if (Base.isInvalid()) |
| 4901 | return SemaRef.ExprError(); |
| 4902 | |
| 4903 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 4904 | BaseType = ((Expr*) Base.get())->getType(); |
| 4905 | } else { |
| 4906 | OldBase = 0; |
| 4907 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 4908 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 4909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4911 | // Transform the first part of the nested-name-specifier that qualifies |
| 4912 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4913 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4914 | = getDerived().TransformFirstQualifierInScope( |
| 4915 | E->getFirstQualifierFoundInScope(), |
| 4916 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4917 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4918 | NestedNameSpecifier *Qualifier = 0; |
| 4919 | if (E->getQualifier()) { |
| 4920 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4921 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4922 | ObjectType, |
| 4923 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4924 | if (!Qualifier) |
| 4925 | return SemaRef.ExprError(); |
| 4926 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4927 | |
| 4928 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4929 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4930 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4931 | if (!Name) |
| 4932 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4933 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4934 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4935 | // This is a reference to a member without an explicitly-specified |
| 4936 | // template argument list. Optimize for this common case. |
| 4937 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4938 | Base.get() == OldBase && |
| 4939 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4940 | Qualifier == E->getQualifier() && |
| 4941 | Name == E->getMember() && |
| 4942 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4943 | return SemaRef.Owned(E->Retain()); |
| 4944 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4945 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4946 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4947 | E->isArrow(), |
| 4948 | E->getOperatorLoc(), |
| 4949 | Qualifier, |
| 4950 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4951 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4952 | Name, |
| 4953 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4954 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4955 | } |
| 4956 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4957 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4958 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4959 | TemplateArgumentLoc Loc; |
| 4960 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4961 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4962 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4963 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4964 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4965 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4966 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4967 | E->isArrow(), |
| 4968 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4969 | Qualifier, |
| 4970 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4971 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4972 | Name, |
| 4973 | E->getMemberLoc(), |
| 4974 | &TransArgs); |
| 4975 | } |
| 4976 | |
| 4977 | template<typename Derived> |
| 4978 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4979 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4980 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4981 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4982 | QualType BaseType; |
| 4983 | if (!Old->isImplicitAccess()) { |
| 4984 | Base = getDerived().TransformExpr(Old->getBase()); |
| 4985 | if (Base.isInvalid()) |
| 4986 | return SemaRef.ExprError(); |
| 4987 | BaseType = ((Expr*) Base.get())->getType(); |
| 4988 | } else { |
| 4989 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 4990 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4991 | |
| 4992 | NestedNameSpecifier *Qualifier = 0; |
| 4993 | if (Old->getQualifier()) { |
| 4994 | Qualifier |
| 4995 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4996 | Old->getQualifierRange()); |
| 4997 | if (Qualifier == 0) |
| 4998 | return SemaRef.ExprError(); |
| 4999 | } |
| 5000 | |
| 5001 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5002 | Sema::LookupOrdinaryName); |
| 5003 | |
| 5004 | // Transform all the decls. |
| 5005 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5006 | E = Old->decls_end(); I != E; ++I) { |
| 5007 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5008 | if (!InstD) { |
| 5009 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5010 | // This can happen because of dependent hiding. |
| 5011 | if (isa<UsingShadowDecl>(*I)) |
| 5012 | continue; |
| 5013 | else |
| 5014 | return SemaRef.ExprError(); |
| 5015 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5016 | |
| 5017 | // Expand using declarations. |
| 5018 | if (isa<UsingDecl>(InstD)) { |
| 5019 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5020 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5021 | E = UD->shadow_end(); I != E; ++I) |
| 5022 | R.addDecl(*I); |
| 5023 | continue; |
| 5024 | } |
| 5025 | |
| 5026 | R.addDecl(InstD); |
| 5027 | } |
| 5028 | |
| 5029 | R.resolveKind(); |
| 5030 | |
| 5031 | TemplateArgumentListInfo TransArgs; |
| 5032 | if (Old->hasExplicitTemplateArgs()) { |
| 5033 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5034 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5035 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5036 | TemplateArgumentLoc Loc; |
| 5037 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5038 | Loc)) |
| 5039 | return SemaRef.ExprError(); |
| 5040 | TransArgs.addArgument(Loc); |
| 5041 | } |
| 5042 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 5043 | |
| 5044 | // FIXME: to do this check properly, we will need to preserve the |
| 5045 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5046 | // base (and therefore couldn't do the check) and a |
| 5047 | // nested-name-qualifier (and therefore could do the lookup). |
| 5048 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5049 | |
| 5050 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5051 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5052 | Old->getOperatorLoc(), |
| 5053 | Old->isArrow(), |
| 5054 | Qualifier, |
| 5055 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame^] | 5056 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5057 | R, |
| 5058 | (Old->hasExplicitTemplateArgs() |
| 5059 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | template<typename Derived> |
| 5063 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5064 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5065 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5066 | } |
| 5067 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5068 | template<typename Derived> |
| 5069 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5070 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5071 | // FIXME: poor source location |
| 5072 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5073 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5074 | if (EncodedType.isNull()) |
| 5075 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5076 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5077 | if (!getDerived().AlwaysRebuild() && |
| 5078 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | |
| 5081 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5082 | EncodedType, |
| 5083 | E->getRParenLoc()); |
| 5084 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5085 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | template<typename Derived> |
| 5087 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5088 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5089 | // FIXME: Implement this! |
| 5090 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5094 | template<typename Derived> |
| 5095 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5096 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5100 | template<typename Derived> |
| 5101 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5102 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5103 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5104 | = cast_or_null<ObjCProtocolDecl>( |
| 5105 | getDerived().TransformDecl(E->getProtocol())); |
| 5106 | if (!Protocol) |
| 5107 | return SemaRef.ExprError(); |
| 5108 | |
| 5109 | if (!getDerived().AlwaysRebuild() && |
| 5110 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | return SemaRef.Owned(E->Retain()); |
| 5112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5113 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5114 | E->getAtLoc(), |
| 5115 | /*FIXME:*/E->getAtLoc(), |
| 5116 | /*FIXME:*/E->getAtLoc(), |
| 5117 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5118 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5121 | template<typename Derived> |
| 5122 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5123 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5124 | // FIXME: Implement this! |
| 5125 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5126 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5129 | template<typename Derived> |
| 5130 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5131 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5132 | // FIXME: Implement this! |
| 5133 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5135 | } |
| 5136 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | template<typename Derived> |
| 5138 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5139 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5140 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5141 | // FIXME: Implement this! |
| 5142 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5143 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | } |
| 5145 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5146 | template<typename Derived> |
| 5147 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5148 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5149 | // FIXME: Implement this! |
| 5150 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5151 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5152 | } |
| 5153 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | template<typename Derived> |
| 5155 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5156 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5157 | // FIXME: Implement this! |
| 5158 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5159 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5162 | template<typename Derived> |
| 5163 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5164 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5165 | bool ArgumentChanged = false; |
| 5166 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5167 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5168 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5169 | if (SubExpr.isInvalid()) |
| 5170 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5173 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5174 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | if (!getDerived().AlwaysRebuild() && |
| 5177 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5178 | return SemaRef.Owned(E->Retain()); |
| 5179 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5181 | move_arg(SubExprs), |
| 5182 | E->getRParenLoc()); |
| 5183 | } |
| 5184 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | template<typename Derived> |
| 5186 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5187 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | // FIXME: Implement this! |
| 5189 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5191 | } |
| 5192 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | template<typename Derived> |
| 5194 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5195 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5196 | // FIXME: Implement this! |
| 5197 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5201 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5202 | // Type reconstruction |
| 5203 | //===----------------------------------------------------------------------===// |
| 5204 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5205 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5206 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5207 | SourceLocation Star) { |
| 5208 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5209 | getDerived().getBaseEntity()); |
| 5210 | } |
| 5211 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5213 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5214 | SourceLocation Star) { |
| 5215 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5216 | getDerived().getBaseEntity()); |
| 5217 | } |
| 5218 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5219 | template<typename Derived> |
| 5220 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5221 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5222 | bool WrittenAsLValue, |
| 5223 | SourceLocation Sigil) { |
| 5224 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5225 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5229 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5230 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5231 | QualType ClassType, |
| 5232 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5233 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5234 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5239 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5240 | SourceLocation Sigil) { |
| 5241 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5242 | getDerived().getBaseEntity()); |
| 5243 | } |
| 5244 | |
| 5245 | template<typename Derived> |
| 5246 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5247 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5248 | ArrayType::ArraySizeModifier SizeMod, |
| 5249 | const llvm::APInt *Size, |
| 5250 | Expr *SizeExpr, |
| 5251 | unsigned IndexTypeQuals, |
| 5252 | SourceRange BracketsRange) { |
| 5253 | if (SizeExpr || !Size) |
| 5254 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5255 | IndexTypeQuals, BracketsRange, |
| 5256 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | |
| 5258 | QualType Types[] = { |
| 5259 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5260 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5261 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5262 | }; |
| 5263 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5264 | QualType SizeType; |
| 5265 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5266 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5267 | SizeType = Types[I]; |
| 5268 | break; |
| 5269 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5270 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5271 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5272 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5273 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5274 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5275 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5276 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5277 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | QualType |
| 5279 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5280 | ArrayType::ArraySizeModifier SizeMod, |
| 5281 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5282 | unsigned IndexTypeQuals, |
| 5283 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5285 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5290 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5291 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5292 | unsigned IndexTypeQuals, |
| 5293 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5294 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5295 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5296 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5298 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5299 | QualType |
| 5300 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5301 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5302 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5303 | unsigned IndexTypeQuals, |
| 5304 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5306 | SizeExpr.takeAs<Expr>(), |
| 5307 | IndexTypeQuals, BracketsRange); |
| 5308 | } |
| 5309 | |
| 5310 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | QualType |
| 5312 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5313 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5314 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5315 | unsigned IndexTypeQuals, |
| 5316 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5318 | SizeExpr.takeAs<Expr>(), |
| 5319 | IndexTypeQuals, BracketsRange); |
| 5320 | } |
| 5321 | |
| 5322 | template<typename Derived> |
| 5323 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5324 | unsigned NumElements) { |
| 5325 | // FIXME: semantic checking! |
| 5326 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5328 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5329 | template<typename Derived> |
| 5330 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5331 | unsigned NumElements, |
| 5332 | SourceLocation AttributeLoc) { |
| 5333 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5334 | NumElements, true); |
| 5335 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5336 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5337 | AttributeLoc); |
| 5338 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5339 | AttributeLoc); |
| 5340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5341 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5342 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5343 | QualType |
| 5344 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5345 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5346 | SourceLocation AttributeLoc) { |
| 5347 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5349 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5350 | template<typename Derived> |
| 5351 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5353 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5354 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5355 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5356 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5357 | Quals, |
| 5358 | getDerived().getBaseLocation(), |
| 5359 | getDerived().getBaseEntity()); |
| 5360 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5361 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5362 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5363 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5364 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5365 | } |
| 5366 | |
| 5367 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5368 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5369 | assert(D && "no decl found"); |
| 5370 | if (D->isInvalidDecl()) return QualType(); |
| 5371 | |
| 5372 | TypeDecl *Ty; |
| 5373 | if (isa<UsingDecl>(D)) { |
| 5374 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5375 | assert(Using->isTypeName() && |
| 5376 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5377 | |
| 5378 | // A valid resolved using typename decl points to exactly one type decl. |
| 5379 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5380 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5381 | |
| 5382 | } else { |
| 5383 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5384 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5385 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5386 | } |
| 5387 | |
| 5388 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5389 | } |
| 5390 | |
| 5391 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5392 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5393 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5394 | } |
| 5395 | |
| 5396 | template<typename Derived> |
| 5397 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5398 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5399 | } |
| 5400 | |
| 5401 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5402 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5403 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5404 | } |
| 5405 | |
| 5406 | template<typename Derived> |
| 5407 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5408 | TemplateName Template, |
| 5409 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5410 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5411 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5413 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5414 | template<typename Derived> |
| 5415 | NestedNameSpecifier * |
| 5416 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5417 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5418 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5419 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5420 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5421 | CXXScopeSpec SS; |
| 5422 | // FIXME: The source location information is all wrong. |
| 5423 | SS.setRange(Range); |
| 5424 | SS.setScopeRep(Prefix); |
| 5425 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5426 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5427 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5428 | ObjectType, |
| 5429 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5430 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | template<typename Derived> |
| 5434 | NestedNameSpecifier * |
| 5435 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5436 | SourceRange Range, |
| 5437 | NamespaceDecl *NS) { |
| 5438 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5439 | } |
| 5440 | |
| 5441 | template<typename Derived> |
| 5442 | NestedNameSpecifier * |
| 5443 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5444 | SourceRange Range, |
| 5445 | bool TemplateKW, |
| 5446 | QualType T) { |
| 5447 | if (T->isDependentType() || T->isRecordType() || |
| 5448 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5449 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5450 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5451 | T.getTypePtr()); |
| 5452 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5453 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5454 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5455 | return 0; |
| 5456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5457 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5458 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5459 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5460 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5461 | bool TemplateKW, |
| 5462 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5464 | Template); |
| 5465 | } |
| 5466 | |
| 5467 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5468 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5469 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5470 | const IdentifierInfo &II, |
| 5471 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5472 | CXXScopeSpec SS; |
| 5473 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5474 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5475 | UnqualifiedId Name; |
| 5476 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5477 | return getSema().ActOnDependentTemplateName( |
| 5478 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5479 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5480 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5481 | ObjectType.getAsOpaquePtr(), |
| 5482 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5483 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5485 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5486 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5487 | TemplateName |
| 5488 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5489 | OverloadedOperatorKind Operator, |
| 5490 | QualType ObjectType) { |
| 5491 | CXXScopeSpec SS; |
| 5492 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5493 | SS.setScopeRep(Qualifier); |
| 5494 | UnqualifiedId Name; |
| 5495 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5496 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5497 | Operator, SymbolLocations); |
| 5498 | return getSema().ActOnDependentTemplateName( |
| 5499 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5500 | SS, |
| 5501 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5502 | ObjectType.getAsOpaquePtr(), |
| 5503 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5504 | .template getAsVal<TemplateName>(); |
| 5505 | } |
| 5506 | |
| 5507 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5508 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5509 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5510 | SourceLocation OpLoc, |
| 5511 | ExprArg Callee, |
| 5512 | ExprArg First, |
| 5513 | ExprArg Second) { |
| 5514 | Expr *FirstExpr = (Expr *)First.get(); |
| 5515 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5516 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5517 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5519 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5520 | if (Op == OO_Subscript) { |
| 5521 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5522 | !SecondExpr->getType()->isOverloadableType()) |
| 5523 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5524 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5525 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5526 | } else if (Op == OO_Arrow) { |
| 5527 | // -> is never a builtin operation. |
| 5528 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5529 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5530 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5531 | // The argument is not of overloadable type, so try to create a |
| 5532 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5533 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5534 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5535 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5536 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5537 | } |
| 5538 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5539 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5540 | !SecondExpr->getType()->isOverloadableType()) { |
| 5541 | // Neither of the arguments is an overloadable type, so try to |
| 5542 | // create a built-in binary operation. |
| 5543 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5544 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5545 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5546 | if (Result.isInvalid()) |
| 5547 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5549 | First.release(); |
| 5550 | Second.release(); |
| 5551 | return move(Result); |
| 5552 | } |
| 5553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5554 | |
| 5555 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5556 | // used during overload resolution. |
| 5557 | Sema::FunctionSet Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5558 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5559 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5560 | assert(ULE->requiresADL()); |
| 5561 | |
| 5562 | // FIXME: Do we have to check |
| 5563 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5564 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5565 | E = ULE->decls_end(); I != E; ++I) |
| 5566 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5567 | } else { |
| 5568 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5569 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 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 | // Add any functions found via argument-dependent lookup. |
| 5573 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5574 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5575 | DeclarationName OpName |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5576 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | 644be85 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5577 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5578 | Functions); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5579 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5580 | // Create the overloaded operator invocation for unary operators. |
| 5581 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5583 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5584 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5585 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5586 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5587 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5588 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5589 | OpLoc, |
| 5590 | move(First), |
| 5591 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5592 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5593 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5597 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5598 | if (Result.isInvalid()) |
| 5599 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5600 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5601 | First.release(); |
| 5602 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5604 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5605 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5606 | } // end namespace clang |
| 5607 | |
| 5608 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |