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. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1017 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1018 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1019 | SourceLocation RParenLoc, |
| 1020 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1021 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1022 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1027 | /// By default, performs semantic analysis to build the new expression. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
| 1029 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1030 | QualType T, |
| 1031 | SourceLocation RParenLoc, |
| 1032 | ExprArg Init) { |
| 1033 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1034 | RParenLoc, move(Init)); |
| 1035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | SourceLocation OpLoc, |
| 1043 | SourceLocation AccessorLoc, |
| 1044 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1045 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1046 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1047 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1048 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1049 | OpLoc, /*IsArrow*/ false, |
| 1050 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1051 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1052 | AccessorLoc, |
| 1053 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1056 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | /// By default, performs semantic analysis to build the new expression. |
| 1059 | /// Subclasses may override this routine to provide different behavior. |
| 1060 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1061 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1062 | SourceLocation RBraceLoc, |
| 1063 | QualType ResultTy) { |
| 1064 | OwningExprResult Result |
| 1065 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1066 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1067 | return move(Result); |
| 1068 | |
| 1069 | // Patch in the result type we were given, which may have been computed |
| 1070 | // when the initial InitListExpr was built. |
| 1071 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1072 | ILE->setType(ResultTy); |
| 1073 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1074 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | /// By default, performs semantic analysis to build the new expression. |
| 1079 | /// Subclasses may override this routine to provide different behavior. |
| 1080 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1081 | MultiExprArg ArrayExprs, |
| 1082 | SourceLocation EqualOrColonLoc, |
| 1083 | bool GNUSyntax, |
| 1084 | ExprArg Init) { |
| 1085 | OwningExprResult Result |
| 1086 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1087 | move(Init)); |
| 1088 | if (Result.isInvalid()) |
| 1089 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1091 | ArrayExprs.release(); |
| 1092 | return move(Result); |
| 1093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1095 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | /// By default, builds the implicit value initialization without performing |
| 1098 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1099 | /// different behavior. |
| 1100 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1101 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1106 | /// By default, performs semantic analysis to build the new expression. |
| 1107 | /// Subclasses may override this routine to provide different behavior. |
| 1108 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1109 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1110 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1111 | RParenLoc); |
| 1112 | } |
| 1113 | |
| 1114 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1116 | /// By default, performs semantic analysis to build the new expression. |
| 1117 | /// Subclasses may override this routine to provide different behavior. |
| 1118 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1119 | MultiExprArg SubExprs, |
| 1120 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1121 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1122 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1123 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | /// |
| 1127 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// rather than attempting to map the label statement itself. |
| 1129 | /// Subclasses may override this routine to provide different behavior. |
| 1130 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1131 | SourceLocation LabelLoc, |
| 1132 | LabelStmt *Label) { |
| 1133 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1136 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | /// By default, performs semantic analysis to build the new expression. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
| 1140 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1141 | StmtArg SubStmt, |
| 1142 | SourceLocation RParenLoc) { |
| 1143 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1146 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1147 | /// |
| 1148 | /// By default, performs semantic analysis to build the new expression. |
| 1149 | /// Subclasses may override this routine to provide different behavior. |
| 1150 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1151 | QualType T1, QualType T2, |
| 1152 | SourceLocation RParenLoc) { |
| 1153 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1154 | T1.getAsOpaquePtr(), |
| 1155 | T2.getAsOpaquePtr(), |
| 1156 | RParenLoc); |
| 1157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1159 | /// \brief Build a new __builtin_choose_expr expression. |
| 1160 | /// |
| 1161 | /// By default, performs semantic analysis to build the new expression. |
| 1162 | /// Subclasses may override this routine to provide different behavior. |
| 1163 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1164 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1165 | SourceLocation RParenLoc) { |
| 1166 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1167 | move(Cond), move(LHS), move(RHS), |
| 1168 | RParenLoc); |
| 1169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1171 | /// \brief Build a new overloaded operator call expression. |
| 1172 | /// |
| 1173 | /// By default, performs semantic analysis to build the new expression. |
| 1174 | /// The semantic analysis provides the behavior of template instantiation, |
| 1175 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1177 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1178 | /// provide different behavior. |
| 1179 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1180 | SourceLocation OpLoc, |
| 1181 | ExprArg Callee, |
| 1182 | ExprArg First, |
| 1183 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1184 | |
| 1185 | /// \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] | 1186 | /// reinterpret_cast. |
| 1187 | /// |
| 1188 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1190 | /// Subclasses may override this routine to provide different behavior. |
| 1191 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1192 | Stmt::StmtClass Class, |
| 1193 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1194 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1195 | SourceLocation RAngleLoc, |
| 1196 | SourceLocation LParenLoc, |
| 1197 | ExprArg SubExpr, |
| 1198 | SourceLocation RParenLoc) { |
| 1199 | switch (Class) { |
| 1200 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1201 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1202 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1203 | move(SubExpr), RParenLoc); |
| 1204 | |
| 1205 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1206 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1210 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1211 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | RAngleLoc, LParenLoc, |
| 1213 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1214 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1217 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | default: |
| 1222 | assert(false && "Invalid C++ named cast"); |
| 1223 | break; |
| 1224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | return getSema().ExprError(); |
| 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 | /// \brief Build a new C++ static_cast expression. |
| 1230 | /// |
| 1231 | /// By default, performs semantic analysis to build the new expression. |
| 1232 | /// Subclasses may override this routine to provide different behavior. |
| 1233 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1234 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1235 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | SourceLocation RAngleLoc, |
| 1237 | SourceLocation LParenLoc, |
| 1238 | ExprArg SubExpr, |
| 1239 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1240 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1241 | TInfo, move(SubExpr), |
| 1242 | SourceRange(LAngleLoc, RAngleLoc), |
| 1243 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /// \brief Build a new C++ dynamic_cast expression. |
| 1247 | /// |
| 1248 | /// By default, performs semantic analysis to build the new expression. |
| 1249 | /// Subclasses may override this routine to provide different behavior. |
| 1250 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1251 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1252 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1253 | SourceLocation RAngleLoc, |
| 1254 | SourceLocation LParenLoc, |
| 1255 | ExprArg SubExpr, |
| 1256 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1257 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1258 | TInfo, move(SubExpr), |
| 1259 | SourceRange(LAngleLoc, RAngleLoc), |
| 1260 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1264 | /// |
| 1265 | /// By default, performs semantic analysis to build the new expression. |
| 1266 | /// Subclasses may override this routine to provide different behavior. |
| 1267 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1268 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1269 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1270 | SourceLocation RAngleLoc, |
| 1271 | SourceLocation LParenLoc, |
| 1272 | ExprArg SubExpr, |
| 1273 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1274 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1275 | TInfo, move(SubExpr), |
| 1276 | SourceRange(LAngleLoc, RAngleLoc), |
| 1277 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1286 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1287 | SourceLocation RAngleLoc, |
| 1288 | SourceLocation LParenLoc, |
| 1289 | ExprArg SubExpr, |
| 1290 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1291 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1292 | TInfo, move(SubExpr), |
| 1293 | SourceRange(LAngleLoc, RAngleLoc), |
| 1294 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1296 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1297 | /// \brief Build a new C++ functional-style cast expression. |
| 1298 | /// |
| 1299 | /// By default, performs semantic analysis to build the new expression. |
| 1300 | /// Subclasses may override this routine to provide different behavior. |
| 1301 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1302 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1303 | SourceLocation LParenLoc, |
| 1304 | ExprArg SubExpr, |
| 1305 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1306 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1308 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1310 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | RParenLoc); |
| 1313 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | /// \brief Build a new C++ typeid(type) expression. |
| 1316 | /// |
| 1317 | /// By default, performs semantic analysis to build the new expression. |
| 1318 | /// Subclasses may override this routine to provide different behavior. |
| 1319 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1320 | SourceLocation LParenLoc, |
| 1321 | QualType T, |
| 1322 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | T.getAsOpaquePtr(), RParenLoc); |
| 1325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1327 | /// \brief Build a new C++ typeid(expr) expression. |
| 1328 | /// |
| 1329 | /// By default, performs semantic analysis to build the new expression. |
| 1330 | /// Subclasses may override this routine to provide different behavior. |
| 1331 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1332 | SourceLocation LParenLoc, |
| 1333 | ExprArg Operand, |
| 1334 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1337 | RParenLoc); |
| 1338 | if (Result.isInvalid()) |
| 1339 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1341 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1342 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1345 | /// \brief Build a new C++ "this" expression. |
| 1346 | /// |
| 1347 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1351 | QualType ThisType, |
| 1352 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1354 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1355 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | /// \brief Build a new C++ throw expression. |
| 1359 | /// |
| 1360 | /// By default, performs semantic analysis to build the new expression. |
| 1361 | /// Subclasses may override this routine to provide different behavior. |
| 1362 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1363 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1364 | } |
| 1365 | |
| 1366 | /// \brief Build a new C++ default-argument expression. |
| 1367 | /// |
| 1368 | /// By default, builds a new default-argument expression, which does not |
| 1369 | /// require any semantic analysis. Subclasses may override this routine to |
| 1370 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1371 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1372 | ParmVarDecl *Param) { |
| 1373 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1374 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /// \brief Build a new C++ zero-initialization expression. |
| 1378 | /// |
| 1379 | /// By default, performs semantic analysis to build the new expression. |
| 1380 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1382 | SourceLocation LParenLoc, |
| 1383 | QualType T, |
| 1384 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1386 | T.getAsOpaquePtr(), LParenLoc, |
| 1387 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1388 | 0, RParenLoc); |
| 1389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1391 | /// \brief Build a new C++ "new" expression. |
| 1392 | /// |
| 1393 | /// By default, performs semantic analysis to build the new expression. |
| 1394 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1396 | bool UseGlobal, |
| 1397 | SourceLocation PlacementLParen, |
| 1398 | MultiExprArg PlacementArgs, |
| 1399 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1400 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1401 | QualType AllocType, |
| 1402 | SourceLocation TypeLoc, |
| 1403 | SourceRange TypeRange, |
| 1404 | ExprArg ArraySize, |
| 1405 | SourceLocation ConstructorLParen, |
| 1406 | MultiExprArg ConstructorArgs, |
| 1407 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | PlacementLParen, |
| 1410 | move(PlacementArgs), |
| 1411 | PlacementRParen, |
| 1412 | ParenTypeId, |
| 1413 | AllocType, |
| 1414 | TypeLoc, |
| 1415 | TypeRange, |
| 1416 | move(ArraySize), |
| 1417 | ConstructorLParen, |
| 1418 | move(ConstructorArgs), |
| 1419 | ConstructorRParen); |
| 1420 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1422 | /// \brief Build a new C++ "delete" expression. |
| 1423 | /// |
| 1424 | /// By default, performs semantic analysis to build the new expression. |
| 1425 | /// Subclasses may override this routine to provide different behavior. |
| 1426 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1427 | bool IsGlobalDelete, |
| 1428 | bool IsArrayForm, |
| 1429 | ExprArg Operand) { |
| 1430 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1431 | move(Operand)); |
| 1432 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | /// \brief Build a new unary type trait expression. |
| 1435 | /// |
| 1436 | /// By default, performs semantic analysis to build the new expression. |
| 1437 | /// Subclasses may override this routine to provide different behavior. |
| 1438 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1439 | SourceLocation StartLoc, |
| 1440 | SourceLocation LParenLoc, |
| 1441 | QualType T, |
| 1442 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1444 | T.getAsOpaquePtr(), RParenLoc); |
| 1445 | } |
| 1446 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | /// expression. |
| 1449 | /// |
| 1450 | /// By default, performs semantic analysis to build the new expression. |
| 1451 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1452 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1453 | SourceRange QualifierRange, |
| 1454 | DeclarationName Name, |
| 1455 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1456 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | CXXScopeSpec SS; |
| 1458 | SS.setRange(QualifierRange); |
| 1459 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1460 | |
| 1461 | if (TemplateArgs) |
| 1462 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1463 | *TemplateArgs); |
| 1464 | |
| 1465 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /// \brief Build a new template-id expression. |
| 1469 | /// |
| 1470 | /// By default, performs semantic analysis to build the new expression. |
| 1471 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1472 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1473 | LookupResult &R, |
| 1474 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1475 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1476 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /// \brief Build a new object-construction expression. |
| 1480 | /// |
| 1481 | /// By default, performs semantic analysis to build the new expression. |
| 1482 | /// Subclasses may override this routine to provide different behavior. |
| 1483 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1484 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | CXXConstructorDecl *Constructor, |
| 1486 | bool IsElidable, |
| 1487 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1488 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1489 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1490 | ConvertedArgs)) |
| 1491 | return getSema().ExprError(); |
| 1492 | |
| 1493 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1494 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /// \brief Build a new object-construction expression. |
| 1498 | /// |
| 1499 | /// By default, performs semantic analysis to build the new expression. |
| 1500 | /// Subclasses may override this routine to provide different behavior. |
| 1501 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1502 | QualType T, |
| 1503 | SourceLocation LParenLoc, |
| 1504 | MultiExprArg Args, |
| 1505 | SourceLocation *Commas, |
| 1506 | SourceLocation RParenLoc) { |
| 1507 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1508 | T.getAsOpaquePtr(), |
| 1509 | LParenLoc, |
| 1510 | move(Args), |
| 1511 | Commas, |
| 1512 | RParenLoc); |
| 1513 | } |
| 1514 | |
| 1515 | /// \brief Build a new object-construction expression. |
| 1516 | /// |
| 1517 | /// By default, performs semantic analysis to build the new expression. |
| 1518 | /// Subclasses may override this routine to provide different behavior. |
| 1519 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1520 | QualType T, |
| 1521 | SourceLocation LParenLoc, |
| 1522 | MultiExprArg Args, |
| 1523 | SourceLocation *Commas, |
| 1524 | SourceLocation RParenLoc) { |
| 1525 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1526 | /*FIXME*/LParenLoc), |
| 1527 | T.getAsOpaquePtr(), |
| 1528 | LParenLoc, |
| 1529 | move(Args), |
| 1530 | Commas, |
| 1531 | RParenLoc); |
| 1532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | /// \brief Build a new member reference expression. |
| 1535 | /// |
| 1536 | /// By default, performs semantic analysis to build the new expression. |
| 1537 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1538 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1539 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1540 | bool IsArrow, |
| 1541 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1542 | NestedNameSpecifier *Qualifier, |
| 1543 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1544 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1545 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1546 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1547 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1549 | SS.setRange(QualifierRange); |
| 1550 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1551 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1552 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1553 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1554 | SS, FirstQualifierInScope, |
| 1555 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1558 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1559 | /// |
| 1560 | /// By default, performs semantic analysis to build the new expression. |
| 1561 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1562 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1563 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1564 | SourceLocation OperatorLoc, |
| 1565 | bool IsArrow, |
| 1566 | NestedNameSpecifier *Qualifier, |
| 1567 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1568 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1569 | LookupResult &R, |
| 1570 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1571 | CXXScopeSpec SS; |
| 1572 | SS.setRange(QualifierRange); |
| 1573 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1574 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1575 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1576 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1577 | SS, FirstQualifierInScope, |
| 1578 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1579 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1581 | /// \brief Build a new Objective-C @encode expression. |
| 1582 | /// |
| 1583 | /// By default, performs semantic analysis to build the new expression. |
| 1584 | /// Subclasses may override this routine to provide different behavior. |
| 1585 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1586 | QualType T, |
| 1587 | SourceLocation RParenLoc) { |
| 1588 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1589 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1590 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | |
| 1592 | /// \brief Build a new Objective-C protocol expression. |
| 1593 | /// |
| 1594 | /// By default, performs semantic analysis to build the new expression. |
| 1595 | /// Subclasses may override this routine to provide different behavior. |
| 1596 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1597 | SourceLocation AtLoc, |
| 1598 | SourceLocation ProtoLoc, |
| 1599 | SourceLocation LParenLoc, |
| 1600 | SourceLocation RParenLoc) { |
| 1601 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1602 | Protocol->getIdentifier(), |
| 1603 | AtLoc, |
| 1604 | ProtoLoc, |
| 1605 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1606 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1609 | /// \brief Build a new shuffle vector expression. |
| 1610 | /// |
| 1611 | /// By default, performs semantic analysis to build the new expression. |
| 1612 | /// Subclasses may override this routine to provide different behavior. |
| 1613 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1614 | MultiExprArg SubExprs, |
| 1615 | SourceLocation RParenLoc) { |
| 1616 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1618 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1619 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1620 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1621 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1623 | // Build a reference to the __builtin_shufflevector builtin |
| 1624 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1627 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1628 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | |
| 1630 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1631 | unsigned NumSubExprs = SubExprs.size(); |
| 1632 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1633 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1634 | Subs, NumSubExprs, |
| 1635 | Builtin->getResultType(), |
| 1636 | RParenLoc); |
| 1637 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1638 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1639 | // Type-check the __builtin_shufflevector expression. |
| 1640 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1641 | if (Result.isInvalid()) |
| 1642 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1645 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1647 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1649 | template<typename Derived> |
| 1650 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1651 | if (!S) |
| 1652 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1654 | switch (S->getStmtClass()) { |
| 1655 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1656 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1657 | // Transform individual statement nodes |
| 1658 | #define STMT(Node, Parent) \ |
| 1659 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1660 | #define EXPR(Node, Parent) |
| 1661 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1663 | // Transform expressions by calling TransformExpr. |
| 1664 | #define STMT(Node, Parent) |
| 1665 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1666 | #include "clang/AST/StmtNodes.def" |
| 1667 | { |
| 1668 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1669 | if (E.isInvalid()) |
| 1670 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1672 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1676 | return SemaRef.Owned(S->Retain()); |
| 1677 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1678 | |
| 1679 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1680 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1681 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1682 | if (!E) |
| 1683 | return SemaRef.Owned(E); |
| 1684 | |
| 1685 | switch (E->getStmtClass()) { |
| 1686 | case Stmt::NoStmtClass: break; |
| 1687 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1688 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1689 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1690 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1697 | NestedNameSpecifier * |
| 1698 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1699 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1700 | QualType ObjectType, |
| 1701 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1702 | if (!NNS) |
| 1703 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1704 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1705 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1706 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1707 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1709 | ObjectType, |
| 1710 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1711 | if (!Prefix) |
| 1712 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | |
| 1714 | // 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] | 1715 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1716 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1717 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1718 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1720 | switch (NNS->getKind()) { |
| 1721 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1723 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1724 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1725 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1726 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | |
| 1728 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1729 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1730 | ObjectType, |
| 1731 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1732 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1733 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1735 | = cast_or_null<NamespaceDecl>( |
| 1736 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1738 | Prefix == NNS->getPrefix() && |
| 1739 | NS == NNS->getAsNamespace()) |
| 1740 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1742 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1745 | case NestedNameSpecifier::Global: |
| 1746 | // There is no meaningful transformation that one could perform on the |
| 1747 | // global scope. |
| 1748 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1750 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1751 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1752 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1753 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1754 | if (T.isNull()) |
| 1755 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1757 | if (!getDerived().AlwaysRebuild() && |
| 1758 | Prefix == NNS->getPrefix() && |
| 1759 | T == QualType(NNS->getAsType(), 0)) |
| 1760 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | |
| 1762 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1763 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1764 | T); |
| 1765 | } |
| 1766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1768 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1774 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1775 | SourceLocation Loc, |
| 1776 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1777 | if (!Name) |
| 1778 | return Name; |
| 1779 | |
| 1780 | switch (Name.getNameKind()) { |
| 1781 | case DeclarationName::Identifier: |
| 1782 | case DeclarationName::ObjCZeroArgSelector: |
| 1783 | case DeclarationName::ObjCOneArgSelector: |
| 1784 | case DeclarationName::ObjCMultiArgSelector: |
| 1785 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1786 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1787 | case DeclarationName::CXXUsingDirective: |
| 1788 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1790 | case DeclarationName::CXXConstructorName: |
| 1791 | case DeclarationName::CXXDestructorName: |
| 1792 | case DeclarationName::CXXConversionFunctionName: { |
| 1793 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1794 | QualType T; |
| 1795 | if (!ObjectType.isNull() && |
| 1796 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1797 | TemplateSpecializationType *SpecType |
| 1798 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1799 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1800 | } else |
| 1801 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1802 | if (T.isNull()) |
| 1803 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1805 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1806 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1807 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1808 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1811 | return DeclarationName(); |
| 1812 | } |
| 1813 | |
| 1814 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1815 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1816 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1817 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1818 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1820 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1821 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1822 | if (!NNS) |
| 1823 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1825 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1827 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1828 | if (!TransTemplate) |
| 1829 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1831 | if (!getDerived().AlwaysRebuild() && |
| 1832 | NNS == QTN->getQualifier() && |
| 1833 | TransTemplate == Template) |
| 1834 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1836 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1837 | TransTemplate); |
| 1838 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1840 | // These should be getting filtered out before they make it into the AST. |
| 1841 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1842 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1844 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1846 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1847 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1848 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1849 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1851 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1852 | NNS == DTN->getQualifier() && |
| 1853 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1854 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1856 | if (DTN->isIdentifier()) |
| 1857 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1858 | ObjectType); |
| 1859 | |
| 1860 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1861 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1864 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1866 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1867 | if (!TransTemplate) |
| 1868 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1869 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1870 | if (!getDerived().AlwaysRebuild() && |
| 1871 | TransTemplate == Template) |
| 1872 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | return TemplateName(TransTemplate); |
| 1875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1877 | // These should be getting filtered out before they reach the AST. |
| 1878 | assert(false && "overloaded function decl survived to here"); |
| 1879 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1883 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1884 | const TemplateArgument &Arg, |
| 1885 | TemplateArgumentLoc &Output) { |
| 1886 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1887 | switch (Arg.getKind()) { |
| 1888 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1889 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | |
| 1892 | case TemplateArgument::Type: |
| 1893 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1894 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1895 | |
| 1896 | break; |
| 1897 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1898 | case TemplateArgument::Template: |
| 1899 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1900 | break; |
| 1901 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1902 | case TemplateArgument::Expression: |
| 1903 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1904 | break; |
| 1905 | |
| 1906 | case TemplateArgument::Declaration: |
| 1907 | case TemplateArgument::Integral: |
| 1908 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1909 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | template<typename Derived> |
| 1915 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1916 | const TemplateArgumentLoc &Input, |
| 1917 | TemplateArgumentLoc &Output) { |
| 1918 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1919 | switch (Arg.getKind()) { |
| 1920 | case TemplateArgument::Null: |
| 1921 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1922 | Output = Input; |
| 1923 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1925 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1926 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1927 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1928 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1929 | |
| 1930 | DI = getDerived().TransformType(DI); |
| 1931 | if (!DI) return true; |
| 1932 | |
| 1933 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1934 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1935 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1936 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1937 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1938 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1939 | DeclarationName Name; |
| 1940 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1941 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1942 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1943 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1944 | if (!D) return true; |
| 1945 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1946 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1947 | if (SourceExpr) { |
| 1948 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1949 | Action::Unevaluated); |
| 1950 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1951 | if (E.isInvalid()) |
| 1952 | SourceExpr = NULL; |
| 1953 | else { |
| 1954 | SourceExpr = E.takeAs<Expr>(); |
| 1955 | SourceExpr->Retain(); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1960 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1961 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1963 | case TemplateArgument::Template: { |
| 1964 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1965 | TemplateName Template |
| 1966 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1967 | if (Template.isNull()) |
| 1968 | return true; |
| 1969 | |
| 1970 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1971 | Input.getTemplateQualifierRange(), |
| 1972 | Input.getTemplateNameLoc()); |
| 1973 | return false; |
| 1974 | } |
| 1975 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1976 | case TemplateArgument::Expression: { |
| 1977 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1978 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1979 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1980 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1981 | Expr *InputExpr = Input.getSourceExpression(); |
| 1982 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1983 | |
| 1984 | Sema::OwningExprResult E |
| 1985 | = getDerived().TransformExpr(InputExpr); |
| 1986 | if (E.isInvalid()) return true; |
| 1987 | |
| 1988 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1989 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1990 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1991 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1992 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1993 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1994 | case TemplateArgument::Pack: { |
| 1995 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 1996 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1998 | AEnd = Arg.pack_end(); |
| 1999 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2000 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2001 | // FIXME: preserve source information here when we start |
| 2002 | // caring about parameter packs. |
| 2003 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2004 | TemplateArgumentLoc InputArg; |
| 2005 | TemplateArgumentLoc OutputArg; |
| 2006 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2007 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2008 | return true; |
| 2009 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2010 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2011 | } |
| 2012 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2014 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2015 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2016 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2017 | } |
| 2018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2019 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2020 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2021 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2024 | //===----------------------------------------------------------------------===// |
| 2025 | // Type transformation |
| 2026 | //===----------------------------------------------------------------------===// |
| 2027 | |
| 2028 | template<typename Derived> |
| 2029 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2030 | if (getDerived().AlreadyTransformed(T)) |
| 2031 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2032 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2033 | // Temporary workaround. All of these transformations should |
| 2034 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2035 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2036 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2037 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2038 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2039 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2040 | if (!NewDI) |
| 2041 | return QualType(); |
| 2042 | |
| 2043 | return NewDI->getType(); |
| 2044 | } |
| 2045 | |
| 2046 | template<typename Derived> |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2047 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2048 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2049 | return DI; |
| 2050 | |
| 2051 | TypeLocBuilder TLB; |
| 2052 | |
| 2053 | TypeLoc TL = DI->getTypeLoc(); |
| 2054 | TLB.reserve(TL.getFullDataSize()); |
| 2055 | |
| 2056 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2057 | if (Result.isNull()) |
| 2058 | return 0; |
| 2059 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2060 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | template<typename Derived> |
| 2064 | QualType |
| 2065 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2066 | switch (T.getTypeLocClass()) { |
| 2067 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2068 | #define TYPELOC(CLASS, PARENT) \ |
| 2069 | case TypeLoc::CLASS: \ |
| 2070 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2071 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2074 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2075 | return QualType(); |
| 2076 | } |
| 2077 | |
| 2078 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2079 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2080 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2081 | /// types). This is the right thing for template instantiation, but |
| 2082 | /// probably not for other clients. |
| 2083 | template<typename Derived> |
| 2084 | QualType |
| 2085 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2086 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2087 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2088 | |
| 2089 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2090 | if (Result.isNull()) |
| 2091 | return QualType(); |
| 2092 | |
| 2093 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2094 | // FIXME: this is the right thing for template instantiation, but |
| 2095 | // probably not for other clients. |
| 2096 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2097 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2098 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2099 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2100 | |
| 2101 | TLB.push<QualifiedTypeLoc>(Result); |
| 2102 | |
| 2103 | // No location information to preserve. |
| 2104 | |
| 2105 | return Result; |
| 2106 | } |
| 2107 | |
| 2108 | template <class TyLoc> static inline |
| 2109 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2110 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2111 | NewT.setNameLoc(T.getNameLoc()); |
| 2112 | return T.getType(); |
| 2113 | } |
| 2114 | |
| 2115 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2116 | // the equivalent template version work. |
| 2117 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2118 | QualType PointeeType \ |
| 2119 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2120 | if (PointeeType.isNull()) \ |
| 2121 | return QualType(); \ |
| 2122 | \ |
| 2123 | QualType Result = TL.getType(); \ |
| 2124 | if (getDerived().AlwaysRebuild() || \ |
| 2125 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2126 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2127 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2128 | if (Result.isNull()) \ |
| 2129 | return QualType(); \ |
| 2130 | } \ |
| 2131 | \ |
| 2132 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2133 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2134 | \ |
| 2135 | return Result; \ |
| 2136 | } while(0) |
| 2137 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2138 | template<typename Derived> |
| 2139 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2140 | BuiltinTypeLoc T) { |
| 2141 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2142 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2143 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2144 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2145 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2146 | ComplexTypeLoc T) { |
| 2147 | // FIXME: recurse? |
| 2148 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2150 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2151 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2152 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2153 | PointerTypeLoc TL) { |
| 2154 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2156 | |
| 2157 | template<typename Derived> |
| 2158 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2159 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2160 | BlockPointerTypeLoc TL) { |
| 2161 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2164 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2165 | /// don't care whether the type itself is an l-value type or an r-value |
| 2166 | /// type; we only care if the type was *written* as an l-value type |
| 2167 | /// or an r-value type. |
| 2168 | template<typename Derived> |
| 2169 | QualType |
| 2170 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2171 | ReferenceTypeLoc TL) { |
| 2172 | const ReferenceType *T = TL.getTypePtr(); |
| 2173 | |
| 2174 | // Note that this works with the pointee-as-written. |
| 2175 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2176 | if (PointeeType.isNull()) |
| 2177 | return QualType(); |
| 2178 | |
| 2179 | QualType Result = TL.getType(); |
| 2180 | if (getDerived().AlwaysRebuild() || |
| 2181 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2182 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2183 | T->isSpelledAsLValue(), |
| 2184 | TL.getSigilLoc()); |
| 2185 | if (Result.isNull()) |
| 2186 | return QualType(); |
| 2187 | } |
| 2188 | |
| 2189 | // r-value references can be rebuilt as l-value references. |
| 2190 | ReferenceTypeLoc NewTL; |
| 2191 | if (isa<LValueReferenceType>(Result)) |
| 2192 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2193 | else |
| 2194 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2195 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2196 | |
| 2197 | return Result; |
| 2198 | } |
| 2199 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2200 | template<typename Derived> |
| 2201 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2202 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2203 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2204 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2207 | template<typename Derived> |
| 2208 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2209 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2210 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2211 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2212 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2213 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2214 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2215 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2216 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2217 | MemberPointerTypeLoc TL) { |
| 2218 | MemberPointerType *T = TL.getTypePtr(); |
| 2219 | |
| 2220 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2221 | if (PointeeType.isNull()) |
| 2222 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2223 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2224 | // TODO: preserve source information for this. |
| 2225 | QualType ClassType |
| 2226 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2227 | if (ClassType.isNull()) |
| 2228 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2229 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2230 | QualType Result = TL.getType(); |
| 2231 | if (getDerived().AlwaysRebuild() || |
| 2232 | PointeeType != T->getPointeeType() || |
| 2233 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2234 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2235 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2236 | if (Result.isNull()) |
| 2237 | return QualType(); |
| 2238 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2239 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2240 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2241 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2242 | |
| 2243 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | template<typename Derived> |
| 2247 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2248 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2249 | ConstantArrayTypeLoc TL) { |
| 2250 | ConstantArrayType *T = TL.getTypePtr(); |
| 2251 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2252 | if (ElementType.isNull()) |
| 2253 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2254 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2255 | QualType Result = TL.getType(); |
| 2256 | if (getDerived().AlwaysRebuild() || |
| 2257 | ElementType != T->getElementType()) { |
| 2258 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2259 | T->getSizeModifier(), |
| 2260 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2261 | T->getIndexTypeCVRQualifiers(), |
| 2262 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2263 | if (Result.isNull()) |
| 2264 | return QualType(); |
| 2265 | } |
| 2266 | |
| 2267 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2268 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2269 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2270 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2271 | Expr *Size = TL.getSizeExpr(); |
| 2272 | if (Size) { |
| 2273 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2274 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2275 | } |
| 2276 | NewTL.setSizeExpr(Size); |
| 2277 | |
| 2278 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2279 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2280 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2281 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2282 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2283 | TypeLocBuilder &TLB, |
| 2284 | IncompleteArrayTypeLoc TL) { |
| 2285 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2286 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2287 | if (ElementType.isNull()) |
| 2288 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2289 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2290 | QualType Result = TL.getType(); |
| 2291 | if (getDerived().AlwaysRebuild() || |
| 2292 | ElementType != T->getElementType()) { |
| 2293 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2294 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2295 | T->getIndexTypeCVRQualifiers(), |
| 2296 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2297 | if (Result.isNull()) |
| 2298 | return QualType(); |
| 2299 | } |
| 2300 | |
| 2301 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2302 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2303 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2304 | NewTL.setSizeExpr(0); |
| 2305 | |
| 2306 | return Result; |
| 2307 | } |
| 2308 | |
| 2309 | template<typename Derived> |
| 2310 | QualType |
| 2311 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2312 | VariableArrayTypeLoc TL) { |
| 2313 | VariableArrayType *T = TL.getTypePtr(); |
| 2314 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2315 | if (ElementType.isNull()) |
| 2316 | return QualType(); |
| 2317 | |
| 2318 | // Array bounds are not potentially evaluated contexts |
| 2319 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2320 | |
| 2321 | Sema::OwningExprResult SizeResult |
| 2322 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2323 | if (SizeResult.isInvalid()) |
| 2324 | return QualType(); |
| 2325 | |
| 2326 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2327 | |
| 2328 | QualType Result = TL.getType(); |
| 2329 | if (getDerived().AlwaysRebuild() || |
| 2330 | ElementType != T->getElementType() || |
| 2331 | Size != T->getSizeExpr()) { |
| 2332 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2333 | T->getSizeModifier(), |
| 2334 | move(SizeResult), |
| 2335 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2336 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2337 | if (Result.isNull()) |
| 2338 | return QualType(); |
| 2339 | } |
| 2340 | else SizeResult.take(); |
| 2341 | |
| 2342 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2343 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2344 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2345 | NewTL.setSizeExpr(Size); |
| 2346 | |
| 2347 | return Result; |
| 2348 | } |
| 2349 | |
| 2350 | template<typename Derived> |
| 2351 | QualType |
| 2352 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2353 | DependentSizedArrayTypeLoc TL) { |
| 2354 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2355 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2356 | if (ElementType.isNull()) |
| 2357 | return QualType(); |
| 2358 | |
| 2359 | // Array bounds are not potentially evaluated contexts |
| 2360 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2361 | |
| 2362 | Sema::OwningExprResult SizeResult |
| 2363 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2364 | if (SizeResult.isInvalid()) |
| 2365 | return QualType(); |
| 2366 | |
| 2367 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2368 | |
| 2369 | QualType Result = TL.getType(); |
| 2370 | if (getDerived().AlwaysRebuild() || |
| 2371 | ElementType != T->getElementType() || |
| 2372 | Size != T->getSizeExpr()) { |
| 2373 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2374 | T->getSizeModifier(), |
| 2375 | move(SizeResult), |
| 2376 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2377 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2378 | if (Result.isNull()) |
| 2379 | return QualType(); |
| 2380 | } |
| 2381 | else SizeResult.take(); |
| 2382 | |
| 2383 | // We might have any sort of array type now, but fortunately they |
| 2384 | // all have the same location layout. |
| 2385 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2386 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2387 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2388 | NewTL.setSizeExpr(Size); |
| 2389 | |
| 2390 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2392 | |
| 2393 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2394 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2395 | TypeLocBuilder &TLB, |
| 2396 | DependentSizedExtVectorTypeLoc TL) { |
| 2397 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2398 | |
| 2399 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2400 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2401 | if (ElementType.isNull()) |
| 2402 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2403 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2404 | // Vector sizes are not potentially evaluated contexts |
| 2405 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2406 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2407 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2408 | if (Size.isInvalid()) |
| 2409 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2410 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2411 | QualType Result = TL.getType(); |
| 2412 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2413 | ElementType != T->getElementType() || |
| 2414 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2415 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2416 | move(Size), |
| 2417 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | if (Result.isNull()) |
| 2419 | return QualType(); |
| 2420 | } |
| 2421 | else Size.take(); |
| 2422 | |
| 2423 | // Result might be dependent or not. |
| 2424 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2425 | DependentSizedExtVectorTypeLoc NewTL |
| 2426 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2427 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2428 | } else { |
| 2429 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2430 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2431 | } |
| 2432 | |
| 2433 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2434 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2435 | |
| 2436 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2437 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2438 | VectorTypeLoc TL) { |
| 2439 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2440 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2441 | if (ElementType.isNull()) |
| 2442 | return QualType(); |
| 2443 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2444 | QualType Result = TL.getType(); |
| 2445 | if (getDerived().AlwaysRebuild() || |
| 2446 | ElementType != T->getElementType()) { |
| 2447 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2448 | if (Result.isNull()) |
| 2449 | return QualType(); |
| 2450 | } |
| 2451 | |
| 2452 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2453 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2454 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2455 | return Result; |
| 2456 | } |
| 2457 | |
| 2458 | template<typename Derived> |
| 2459 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2460 | ExtVectorTypeLoc TL) { |
| 2461 | VectorType *T = TL.getTypePtr(); |
| 2462 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2463 | if (ElementType.isNull()) |
| 2464 | return QualType(); |
| 2465 | |
| 2466 | QualType Result = TL.getType(); |
| 2467 | if (getDerived().AlwaysRebuild() || |
| 2468 | ElementType != T->getElementType()) { |
| 2469 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2470 | T->getNumElements(), |
| 2471 | /*FIXME*/ SourceLocation()); |
| 2472 | if (Result.isNull()) |
| 2473 | return QualType(); |
| 2474 | } |
| 2475 | |
| 2476 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2477 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2478 | |
| 2479 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2481 | |
| 2482 | template<typename Derived> |
| 2483 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2484 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2485 | FunctionProtoTypeLoc TL) { |
| 2486 | FunctionProtoType *T = TL.getTypePtr(); |
| 2487 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2488 | if (ResultType.isNull()) |
| 2489 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2490 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2491 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2492 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2493 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2494 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2495 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2496 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | QualType NewType; |
| 2498 | ParmVarDecl *NewParm; |
| 2499 | |
| 2500 | if (OldParm) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2501 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2502 | assert(OldDI->getType() == T->getArgType(i)); |
| 2503 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2504 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2505 | if (!NewDI) |
| 2506 | return QualType(); |
| 2507 | |
| 2508 | if (NewDI == OldDI) |
| 2509 | NewParm = OldParm; |
| 2510 | else |
| 2511 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2512 | OldParm->getDeclContext(), |
| 2513 | OldParm->getLocation(), |
| 2514 | OldParm->getIdentifier(), |
| 2515 | NewDI->getType(), |
| 2516 | NewDI, |
| 2517 | OldParm->getStorageClass(), |
| 2518 | /* DefArg */ NULL); |
| 2519 | NewType = NewParm->getType(); |
| 2520 | |
| 2521 | // Deal with the possibility that we don't have a parameter |
| 2522 | // declaration for this parameter. |
| 2523 | } else { |
| 2524 | NewParm = 0; |
| 2525 | |
| 2526 | QualType OldType = T->getArgType(i); |
| 2527 | NewType = getDerived().TransformType(OldType); |
| 2528 | if (NewType.isNull()) |
| 2529 | return QualType(); |
| 2530 | } |
| 2531 | |
| 2532 | ParamTypes.push_back(NewType); |
| 2533 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2535 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2536 | QualType Result = TL.getType(); |
| 2537 | if (getDerived().AlwaysRebuild() || |
| 2538 | ResultType != T->getResultType() || |
| 2539 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2540 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2541 | ParamTypes.data(), |
| 2542 | ParamTypes.size(), |
| 2543 | T->isVariadic(), |
| 2544 | T->getTypeQuals()); |
| 2545 | if (Result.isNull()) |
| 2546 | return QualType(); |
| 2547 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2548 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2549 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2550 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2551 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2552 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2553 | NewTL.setArg(i, ParamDecls[i]); |
| 2554 | |
| 2555 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2556 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2558 | template<typename Derived> |
| 2559 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2560 | TypeLocBuilder &TLB, |
| 2561 | FunctionNoProtoTypeLoc TL) { |
| 2562 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2563 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2564 | if (ResultType.isNull()) |
| 2565 | return QualType(); |
| 2566 | |
| 2567 | QualType Result = TL.getType(); |
| 2568 | if (getDerived().AlwaysRebuild() || |
| 2569 | ResultType != T->getResultType()) |
| 2570 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2571 | |
| 2572 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2573 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2574 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2575 | |
| 2576 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2579 | template<typename Derived> QualType |
| 2580 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2581 | UnresolvedUsingTypeLoc TL) { |
| 2582 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2583 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2584 | if (!D) |
| 2585 | return QualType(); |
| 2586 | |
| 2587 | QualType Result = TL.getType(); |
| 2588 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2589 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2590 | if (Result.isNull()) |
| 2591 | return QualType(); |
| 2592 | } |
| 2593 | |
| 2594 | // We might get an arbitrary type spec type back. We should at |
| 2595 | // least always get a type spec type, though. |
| 2596 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2597 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2598 | |
| 2599 | return Result; |
| 2600 | } |
| 2601 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2602 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2603 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2604 | TypedefTypeLoc TL) { |
| 2605 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2606 | TypedefDecl *Typedef |
| 2607 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2608 | if (!Typedef) |
| 2609 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2611 | QualType Result = TL.getType(); |
| 2612 | if (getDerived().AlwaysRebuild() || |
| 2613 | Typedef != T->getDecl()) { |
| 2614 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2615 | if (Result.isNull()) |
| 2616 | return QualType(); |
| 2617 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2618 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2619 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2620 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2621 | |
| 2622 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2624 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2626 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2627 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2628 | // typeof expressions are not potentially evaluated contexts |
| 2629 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2630 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2631 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2632 | if (E.isInvalid()) |
| 2633 | return QualType(); |
| 2634 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2635 | QualType Result = TL.getType(); |
| 2636 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2637 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2638 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2639 | if (Result.isNull()) |
| 2640 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2641 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2642 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2643 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2645 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2646 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2647 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2648 | |
| 2649 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2650 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2651 | |
| 2652 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2653 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2654 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2655 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2656 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2657 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2658 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2659 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2660 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2661 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2662 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2663 | if (Result.isNull()) |
| 2664 | return QualType(); |
| 2665 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2666 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2667 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2668 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2669 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2670 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2671 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2672 | |
| 2673 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2674 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2675 | |
| 2676 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2677 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2678 | DecltypeTypeLoc TL) { |
| 2679 | DecltypeType *T = TL.getTypePtr(); |
| 2680 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2681 | // decltype expressions are not potentially evaluated contexts |
| 2682 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2683 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2684 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2685 | if (E.isInvalid()) |
| 2686 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2688 | QualType Result = TL.getType(); |
| 2689 | if (getDerived().AlwaysRebuild() || |
| 2690 | E.get() != T->getUnderlyingExpr()) { |
| 2691 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2692 | if (Result.isNull()) |
| 2693 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2694 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2695 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2696 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2697 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2698 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2699 | |
| 2700 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2704 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2705 | RecordTypeLoc TL) { |
| 2706 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2707 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2708 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2709 | if (!Record) |
| 2710 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2712 | QualType Result = TL.getType(); |
| 2713 | if (getDerived().AlwaysRebuild() || |
| 2714 | Record != T->getDecl()) { |
| 2715 | Result = getDerived().RebuildRecordType(Record); |
| 2716 | if (Result.isNull()) |
| 2717 | return QualType(); |
| 2718 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2719 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2720 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2721 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2722 | |
| 2723 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
| 2726 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2727 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2728 | EnumTypeLoc TL) { |
| 2729 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2730 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2731 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2732 | if (!Enum) |
| 2733 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2734 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2735 | QualType Result = TL.getType(); |
| 2736 | if (getDerived().AlwaysRebuild() || |
| 2737 | Enum != T->getDecl()) { |
| 2738 | Result = getDerived().RebuildEnumType(Enum); |
| 2739 | if (Result.isNull()) |
| 2740 | return QualType(); |
| 2741 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2743 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2744 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2745 | |
| 2746 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2748 | |
| 2749 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2751 | ElaboratedTypeLoc TL) { |
| 2752 | ElaboratedType *T = TL.getTypePtr(); |
| 2753 | |
| 2754 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2755 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2756 | if (Underlying.isNull()) |
| 2757 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2758 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2759 | QualType Result = TL.getType(); |
| 2760 | if (getDerived().AlwaysRebuild() || |
| 2761 | Underlying != T->getUnderlyingType()) { |
| 2762 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2763 | if (Result.isNull()) |
| 2764 | return QualType(); |
| 2765 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2766 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2767 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2768 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2769 | |
| 2770 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2772 | |
| 2773 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2774 | template<typename Derived> |
| 2775 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | TypeLocBuilder &TLB, |
| 2777 | TemplateTypeParmTypeLoc TL) { |
| 2778 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2782 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | TypeLocBuilder &TLB, |
| 2784 | SubstTemplateTypeParmTypeLoc TL) { |
| 2785 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2789 | inline QualType |
| 2790 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2791 | TypeLocBuilder &TLB, |
| 2792 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2793 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2794 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2796 | template<typename Derived> |
| 2797 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2798 | const TemplateSpecializationType *TST, |
| 2799 | QualType ObjectType) { |
| 2800 | // FIXME: this entire method is a temporary workaround; callers |
| 2801 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2803 | // Fake up a TemplateSpecializationTypeLoc. |
| 2804 | TypeLocBuilder TLB; |
| 2805 | TemplateSpecializationTypeLoc TL |
| 2806 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2807 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2808 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2809 | |
| 2810 | TL.setTemplateNameLoc(BaseLoc); |
| 2811 | TL.setLAngleLoc(BaseLoc); |
| 2812 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2813 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2814 | const TemplateArgument &TA = TST->getArg(i); |
| 2815 | TemplateArgumentLoc TAL; |
| 2816 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2817 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2818 | } |
| 2819 | |
| 2820 | TypeLocBuilder IgnoredTLB; |
| 2821 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2825 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2826 | TypeLocBuilder &TLB, |
| 2827 | TemplateSpecializationTypeLoc TL, |
| 2828 | QualType ObjectType) { |
| 2829 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2830 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2831 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2832 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | if (Template.isNull()) |
| 2834 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2836 | TemplateArgumentListInfo NewTemplateArgs; |
| 2837 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2838 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2839 | |
| 2840 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2841 | TemplateArgumentLoc Loc; |
| 2842 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2843 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2844 | NewTemplateArgs.addArgument(Loc); |
| 2845 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2846 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2847 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2848 | |
| 2849 | QualType Result = |
| 2850 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2851 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2852 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2853 | |
| 2854 | if (!Result.isNull()) { |
| 2855 | TemplateSpecializationTypeLoc NewTL |
| 2856 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2857 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2858 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2859 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2860 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2861 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2864 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2865 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2866 | |
| 2867 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2868 | QualType |
| 2869 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2870 | QualifiedNameTypeLoc TL) { |
| 2871 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2872 | NestedNameSpecifier *NNS |
| 2873 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2874 | SourceRange()); |
| 2875 | if (!NNS) |
| 2876 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2878 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2879 | if (Named.isNull()) |
| 2880 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2882 | QualType Result = TL.getType(); |
| 2883 | if (getDerived().AlwaysRebuild() || |
| 2884 | NNS != T->getQualifier() || |
| 2885 | Named != T->getNamedType()) { |
| 2886 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2887 | if (Result.isNull()) |
| 2888 | return QualType(); |
| 2889 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2890 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2891 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2892 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2893 | |
| 2894 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2896 | |
| 2897 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2898 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2899 | TypenameTypeLoc TL) { |
| 2900 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2901 | |
| 2902 | /* FIXME: preserve source information better than this */ |
| 2903 | SourceRange SR(TL.getNameLoc()); |
| 2904 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2905 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2906 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2907 | if (!NNS) |
| 2908 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2909 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2910 | QualType Result; |
| 2911 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2912 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2913 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2914 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2915 | if (NewTemplateId.isNull()) |
| 2916 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2917 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2918 | if (!getDerived().AlwaysRebuild() && |
| 2919 | NNS == T->getQualifier() && |
| 2920 | NewTemplateId == QualType(TemplateId, 0)) |
| 2921 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2923 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2924 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2925 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2926 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | if (Result.isNull()) |
| 2928 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2930 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2931 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2932 | |
| 2933 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2935 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2936 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2937 | QualType |
| 2938 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2939 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2940 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2941 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2942 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
| 2944 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2945 | QualType |
| 2946 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2947 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2948 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2949 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2952 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2953 | // Statement transformation |
| 2954 | //===----------------------------------------------------------------------===// |
| 2955 | template<typename Derived> |
| 2956 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2957 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2958 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | template<typename Derived> |
| 2962 | Sema::OwningStmtResult |
| 2963 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2964 | return getDerived().TransformCompoundStmt(S, false); |
| 2965 | } |
| 2966 | |
| 2967 | template<typename Derived> |
| 2968 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2970 | bool IsStmtExpr) { |
| 2971 | bool SubStmtChanged = false; |
| 2972 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2973 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2974 | B != BEnd; ++B) { |
| 2975 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2976 | if (Result.isInvalid()) |
| 2977 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2978 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2979 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2980 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2982 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2983 | if (!getDerived().AlwaysRebuild() && |
| 2984 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2985 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2986 | |
| 2987 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2988 | move_arg(Statements), |
| 2989 | S->getRBracLoc(), |
| 2990 | IsStmtExpr); |
| 2991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2993 | template<typename Derived> |
| 2994 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 2996 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 2997 | { |
| 2998 | // The case value expressions are not potentially evaluated. |
| 2999 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3001 | // Transform the left-hand case value. |
| 3002 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3003 | if (LHS.isInvalid()) |
| 3004 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3005 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3006 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3007 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3008 | if (RHS.isInvalid()) |
| 3009 | return SemaRef.StmtError(); |
| 3010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3012 | // Build the case statement. |
| 3013 | // Case statements are always rebuilt so that they will attached to their |
| 3014 | // transformed switch statement. |
| 3015 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3016 | move(LHS), |
| 3017 | S->getEllipsisLoc(), |
| 3018 | move(RHS), |
| 3019 | S->getColonLoc()); |
| 3020 | if (Case.isInvalid()) |
| 3021 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3023 | // Transform the statement following the case |
| 3024 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3025 | if (SubStmt.isInvalid()) |
| 3026 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3028 | // Attach the body to the case statement |
| 3029 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3030 | } |
| 3031 | |
| 3032 | template<typename Derived> |
| 3033 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3035 | // Transform the statement following the default case |
| 3036 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3037 | if (SubStmt.isInvalid()) |
| 3038 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3040 | // Default statements are always rebuilt |
| 3041 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3042 | move(SubStmt)); |
| 3043 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3045 | template<typename Derived> |
| 3046 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3048 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3049 | if (SubStmt.isInvalid()) |
| 3050 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3051 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3052 | // FIXME: Pass the real colon location in. |
| 3053 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3054 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3055 | move(SubStmt)); |
| 3056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3058 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3059 | Sema::OwningStmtResult |
| 3060 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3061 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3062 | OwningExprResult Cond(SemaRef); |
| 3063 | VarDecl *ConditionVar = 0; |
| 3064 | if (S->getConditionVariable()) { |
| 3065 | ConditionVar |
| 3066 | = cast_or_null<VarDecl>( |
| 3067 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3068 | if (!ConditionVar) |
| 3069 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3070 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3071 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3072 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3073 | if (Cond.isInvalid()) |
| 3074 | return SemaRef.StmtError(); |
| 3075 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3076 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3077 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3079 | // Transform the "then" branch. |
| 3080 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3081 | if (Then.isInvalid()) |
| 3082 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3084 | // Transform the "else" branch. |
| 3085 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3086 | if (Else.isInvalid()) |
| 3087 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3089 | if (!getDerived().AlwaysRebuild() && |
| 3090 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3091 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3092 | Then.get() == S->getThen() && |
| 3093 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | return SemaRef.Owned(S->Retain()); |
| 3095 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3096 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3097 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | template<typename Derived> |
| 3102 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3104 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3105 | OwningExprResult Cond(SemaRef); |
| 3106 | VarDecl *ConditionVar = 0; |
| 3107 | if (S->getConditionVariable()) { |
| 3108 | ConditionVar |
| 3109 | = cast_or_null<VarDecl>( |
| 3110 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3111 | if (!ConditionVar) |
| 3112 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3113 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3114 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3115 | |
| 3116 | if (Cond.isInvalid()) |
| 3117 | return SemaRef.StmtError(); |
| 3118 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3119 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3120 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3121 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3123 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3124 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3125 | if (Switch.isInvalid()) |
| 3126 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | // Transform the body of the switch statement. |
| 3129 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3130 | if (Body.isInvalid()) |
| 3131 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3133 | // Complete the switch statement. |
| 3134 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3135 | move(Body)); |
| 3136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3138 | template<typename Derived> |
| 3139 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3140 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3141 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3142 | OwningExprResult Cond(SemaRef); |
| 3143 | VarDecl *ConditionVar = 0; |
| 3144 | if (S->getConditionVariable()) { |
| 3145 | ConditionVar |
| 3146 | = cast_or_null<VarDecl>( |
| 3147 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3148 | if (!ConditionVar) |
| 3149 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3150 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3151 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3152 | |
| 3153 | if (Cond.isInvalid()) |
| 3154 | return SemaRef.StmtError(); |
| 3155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3156 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3157 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | // Transform the body |
| 3160 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3161 | if (Body.isInvalid()) |
| 3162 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3163 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3164 | if (!getDerived().AlwaysRebuild() && |
| 3165 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3166 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | return SemaRef.Owned(S->Retain()); |
| 3169 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3170 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3171 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3174 | template<typename Derived> |
| 3175 | Sema::OwningStmtResult |
| 3176 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3177 | // Transform the condition |
| 3178 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3179 | if (Cond.isInvalid()) |
| 3180 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | // Transform the body |
| 3183 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3184 | if (Body.isInvalid()) |
| 3185 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3187 | if (!getDerived().AlwaysRebuild() && |
| 3188 | Cond.get() == S->getCond() && |
| 3189 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | return SemaRef.Owned(S->Retain()); |
| 3191 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3192 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3193 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3194 | S->getRParenLoc()); |
| 3195 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3197 | template<typename Derived> |
| 3198 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3199 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3200 | // Transform the initialization statement |
| 3201 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3202 | if (Init.isInvalid()) |
| 3203 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3205 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3206 | OwningExprResult Cond(SemaRef); |
| 3207 | VarDecl *ConditionVar = 0; |
| 3208 | if (S->getConditionVariable()) { |
| 3209 | ConditionVar |
| 3210 | = cast_or_null<VarDecl>( |
| 3211 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3212 | if (!ConditionVar) |
| 3213 | return SemaRef.StmtError(); |
| 3214 | } else { |
| 3215 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3216 | |
| 3217 | if (Cond.isInvalid()) |
| 3218 | return SemaRef.StmtError(); |
| 3219 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | // Transform the increment |
| 3222 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3223 | if (Inc.isInvalid()) |
| 3224 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | // Transform the body |
| 3227 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3228 | if (Body.isInvalid()) |
| 3229 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | if (!getDerived().AlwaysRebuild() && |
| 3232 | Init.get() == S->getInit() && |
| 3233 | Cond.get() == S->getCond() && |
| 3234 | Inc.get() == S->getInc() && |
| 3235 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3236 | return SemaRef.Owned(S->Retain()); |
| 3237 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3238 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3239 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3240 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3241 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | S->getRParenLoc(), move(Body)); |
| 3243 | } |
| 3244 | |
| 3245 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | Sema::OwningStmtResult |
| 3247 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3248 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3249 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3250 | S->getLabel()); |
| 3251 | } |
| 3252 | |
| 3253 | template<typename Derived> |
| 3254 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3257 | if (Target.isInvalid()) |
| 3258 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3260 | if (!getDerived().AlwaysRebuild() && |
| 3261 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3263 | |
| 3264 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3265 | move(Target)); |
| 3266 | } |
| 3267 | |
| 3268 | template<typename Derived> |
| 3269 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3271 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3272 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3274 | template<typename Derived> |
| 3275 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3276 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3277 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3280 | template<typename Derived> |
| 3281 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3284 | if (Result.isInvalid()) |
| 3285 | return SemaRef.StmtError(); |
| 3286 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3288 | // to tell whether the return type of the function has changed. |
| 3289 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | template<typename Derived> |
| 3293 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3294 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3295 | bool DeclChanged = false; |
| 3296 | llvm::SmallVector<Decl *, 4> Decls; |
| 3297 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3298 | D != DEnd; ++D) { |
| 3299 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3300 | if (!Transformed) |
| 3301 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3302 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3303 | if (Transformed != *D) |
| 3304 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3306 | Decls.push_back(Transformed); |
| 3307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | return SemaRef.Owned(S->Retain()); |
| 3311 | |
| 3312 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | S->getStartLoc(), S->getEndLoc()); |
| 3314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3316 | template<typename Derived> |
| 3317 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3318 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3319 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | template<typename Derived> |
| 3324 | Sema::OwningStmtResult |
| 3325 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3326 | // FIXME: Implement! |
| 3327 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | |
| 3332 | template<typename Derived> |
| 3333 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | // FIXME: Implement this |
| 3336 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3339 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3340 | template<typename Derived> |
| 3341 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | // FIXME: Implement this |
| 3344 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3345 | return SemaRef.Owned(S->Retain()); |
| 3346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3347 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3348 | template<typename Derived> |
| 3349 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | // FIXME: Implement this |
| 3352 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3356 | template<typename Derived> |
| 3357 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | // FIXME: Implement this |
| 3360 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3361 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3363 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3364 | template<typename Derived> |
| 3365 | Sema::OwningStmtResult |
| 3366 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | // FIXME: Implement this |
| 3369 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3370 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | template<typename Derived> |
| 3374 | Sema::OwningStmtResult |
| 3375 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3377 | // FIXME: Implement this |
| 3378 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | template<typename Derived> |
| 3384 | Sema::OwningStmtResult |
| 3385 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3386 | // Transform the exception declaration, if any. |
| 3387 | VarDecl *Var = 0; |
| 3388 | if (S->getExceptionDecl()) { |
| 3389 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3390 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3391 | ExceptionDecl->getDeclName()); |
| 3392 | |
| 3393 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3394 | if (T.isNull()) |
| 3395 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3396 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3397 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3398 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3399 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3400 | ExceptionDecl->getIdentifier(), |
| 3401 | ExceptionDecl->getLocation(), |
| 3402 | /*FIXME: Inaccurate*/ |
| 3403 | SourceRange(ExceptionDecl->getLocation())); |
| 3404 | if (!Var || Var->isInvalidDecl()) { |
| 3405 | if (Var) |
| 3406 | Var->Destroy(SemaRef.Context); |
| 3407 | return SemaRef.StmtError(); |
| 3408 | } |
| 3409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3411 | // Transform the actual exception handler. |
| 3412 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3413 | if (Handler.isInvalid()) { |
| 3414 | if (Var) |
| 3415 | Var->Destroy(SemaRef.Context); |
| 3416 | return SemaRef.StmtError(); |
| 3417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3418 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3419 | if (!getDerived().AlwaysRebuild() && |
| 3420 | !Var && |
| 3421 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3423 | |
| 3424 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3425 | Var, |
| 3426 | move(Handler)); |
| 3427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | template<typename Derived> |
| 3430 | Sema::OwningStmtResult |
| 3431 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3432 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3433 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3435 | if (TryBlock.isInvalid()) |
| 3436 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | // Transform the handlers. |
| 3439 | bool HandlerChanged = false; |
| 3440 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3441 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3443 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3444 | if (Handler.isInvalid()) |
| 3445 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3448 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3449 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3451 | if (!getDerived().AlwaysRebuild() && |
| 3452 | TryBlock.get() == S->getTryBlock() && |
| 3453 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | |
| 3456 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3458 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3459 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3460 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3461 | // Expression transformation |
| 3462 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | template<typename Derived> |
| 3464 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3465 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3466 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3467 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3468 | |
| 3469 | template<typename Derived> |
| 3470 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3471 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3472 | NestedNameSpecifier *Qualifier = 0; |
| 3473 | if (E->getQualifier()) { |
| 3474 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3475 | E->getQualifierRange()); |
| 3476 | if (!Qualifier) |
| 3477 | return SemaRef.ExprError(); |
| 3478 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3479 | |
| 3480 | ValueDecl *ND |
| 3481 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3482 | if (!ND) |
| 3483 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3484 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3485 | if (!getDerived().AlwaysRebuild() && |
| 3486 | Qualifier == E->getQualifier() && |
| 3487 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3488 | !E->hasExplicitTemplateArgumentList()) { |
| 3489 | |
| 3490 | // Mark it referenced in the new context regardless. |
| 3491 | // FIXME: this is a bit instantiation-specific. |
| 3492 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3493 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3494 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3495 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3496 | |
| 3497 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3498 | if (E->hasExplicitTemplateArgumentList()) { |
| 3499 | TemplateArgs = &TransArgs; |
| 3500 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3501 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3502 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3503 | TemplateArgumentLoc Loc; |
| 3504 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3505 | return SemaRef.ExprError(); |
| 3506 | TransArgs.addArgument(Loc); |
| 3507 | } |
| 3508 | } |
| 3509 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3510 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3511 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3514 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3515 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3516 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3520 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3522 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3525 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3526 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3528 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3529 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3530 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3532 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3534 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3536 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3538 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3540 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | return SemaRef.Owned(E->Retain()); |
| 3542 | } |
| 3543 | |
| 3544 | template<typename Derived> |
| 3545 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3546 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3547 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3548 | if (SubExpr.isInvalid()) |
| 3549 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3550 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3551 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | return SemaRef.Owned(E->Retain()); |
| 3553 | |
| 3554 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3555 | E->getRParen()); |
| 3556 | } |
| 3557 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | template<typename Derived> |
| 3559 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3560 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3561 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3562 | if (SubExpr.isInvalid()) |
| 3563 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3565 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3566 | return SemaRef.Owned(E->Retain()); |
| 3567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3568 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3569 | E->getOpcode(), |
| 3570 | move(SubExpr)); |
| 3571 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3572 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3573 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3575 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3576 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3577 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3578 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3579 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3580 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3581 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3583 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3584 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3586 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3587 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3588 | E->getSourceRange()); |
| 3589 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3591 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3592 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3593 | // C++0x [expr.sizeof]p1: |
| 3594 | // The operand is either an expression, which is an unevaluated operand |
| 3595 | // [...] |
| 3596 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3597 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3598 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3599 | if (SubExpr.isInvalid()) |
| 3600 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3602 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3603 | return SemaRef.Owned(E->Retain()); |
| 3604 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3606 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3607 | E->isSizeOf(), |
| 3608 | E->getSourceRange()); |
| 3609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3611 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3613 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3614 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3615 | if (LHS.isInvalid()) |
| 3616 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3617 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3618 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3619 | if (RHS.isInvalid()) |
| 3620 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | |
| 3622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3623 | if (!getDerived().AlwaysRebuild() && |
| 3624 | LHS.get() == E->getLHS() && |
| 3625 | RHS.get() == E->getRHS()) |
| 3626 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3628 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3629 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3630 | move(RHS), |
| 3631 | E->getRBracketLoc()); |
| 3632 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3633 | |
| 3634 | template<typename Derived> |
| 3635 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3636 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3637 | // Transform the callee. |
| 3638 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3639 | if (Callee.isInvalid()) |
| 3640 | return SemaRef.ExprError(); |
| 3641 | |
| 3642 | // Transform arguments. |
| 3643 | bool ArgChanged = false; |
| 3644 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3645 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3646 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3647 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3648 | if (Arg.isInvalid()) |
| 3649 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3651 | // FIXME: Wrong source location information for the ','. |
| 3652 | FakeCommaLocs.push_back( |
| 3653 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | |
| 3655 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3656 | Args.push_back(Arg.takeAs<Expr>()); |
| 3657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3659 | if (!getDerived().AlwaysRebuild() && |
| 3660 | Callee.get() == E->getCallee() && |
| 3661 | !ArgChanged) |
| 3662 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3664 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3666 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3667 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3668 | move_arg(Args), |
| 3669 | FakeCommaLocs.data(), |
| 3670 | E->getRParenLoc()); |
| 3671 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | |
| 3673 | template<typename Derived> |
| 3674 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3675 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3676 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3677 | if (Base.isInvalid()) |
| 3678 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3679 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3680 | NestedNameSpecifier *Qualifier = 0; |
| 3681 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3683 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3684 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3685 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3686 | return SemaRef.ExprError(); |
| 3687 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3689 | ValueDecl *Member |
| 3690 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3691 | if (!Member) |
| 3692 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3694 | if (!getDerived().AlwaysRebuild() && |
| 3695 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3696 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3697 | Member == E->getMemberDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3698 | !E->hasExplicitTemplateArgumentList()) { |
| 3699 | |
| 3700 | // Mark it referenced in the new context regardless. |
| 3701 | // FIXME: this is a bit instantiation-specific. |
| 3702 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3703 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3704 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3705 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3706 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3707 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3708 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3709 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3710 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3711 | TemplateArgumentLoc Loc; |
| 3712 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3713 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3714 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3718 | // FIXME: Bogus source location for the operator |
| 3719 | SourceLocation FakeOperatorLoc |
| 3720 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3721 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3722 | // FIXME: to do this check properly, we will need to preserve the |
| 3723 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3724 | // base (and therefore couldn't do the check) and a |
| 3725 | // nested-name-qualifier (and therefore could do the lookup). |
| 3726 | NamedDecl *FirstQualifierInScope = 0; |
| 3727 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3728 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3729 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3730 | Qualifier, |
| 3731 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3732 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3733 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3734 | (E->hasExplicitTemplateArgumentList() |
| 3735 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3736 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3737 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3739 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3740 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3741 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | assert(false && "Cannot transform abstract class"); |
| 3743 | return SemaRef.Owned(E->Retain()); |
| 3744 | } |
| 3745 | |
| 3746 | template<typename Derived> |
| 3747 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3748 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3749 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3750 | if (LHS.isInvalid()) |
| 3751 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3753 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3754 | if (RHS.isInvalid()) |
| 3755 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3757 | if (!getDerived().AlwaysRebuild() && |
| 3758 | LHS.get() == E->getLHS() && |
| 3759 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | return SemaRef.Owned(E->Retain()); |
| 3761 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3762 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3763 | move(LHS), move(RHS)); |
| 3764 | } |
| 3765 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3766 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3767 | Sema::OwningExprResult |
| 3768 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3769 | CompoundAssignOperator *E) { |
| 3770 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3773 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3774 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3775 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3777 | if (Cond.isInvalid()) |
| 3778 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3780 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3781 | if (LHS.isInvalid()) |
| 3782 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3784 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3785 | if (RHS.isInvalid()) |
| 3786 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3788 | if (!getDerived().AlwaysRebuild() && |
| 3789 | Cond.get() == E->getCond() && |
| 3790 | LHS.get() == E->getLHS() && |
| 3791 | RHS.get() == E->getRHS()) |
| 3792 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3793 | |
| 3794 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3795 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3796 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3797 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3798 | move(RHS)); |
| 3799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3800 | |
| 3801 | template<typename Derived> |
| 3802 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3803 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3804 | // Implicit casts are eliminated during transformation, since they |
| 3805 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3806 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3807 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3809 | template<typename Derived> |
| 3810 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3811 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3812 | assert(false && "Cannot transform abstract class"); |
| 3813 | return SemaRef.Owned(E->Retain()); |
| 3814 | } |
| 3815 | |
| 3816 | template<typename Derived> |
| 3817 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3818 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3819 | TypeSourceInfo *OldT; |
| 3820 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3821 | { |
| 3822 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3823 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3824 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3825 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3826 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3827 | OldT = E->getTypeInfoAsWritten(); |
| 3828 | NewT = getDerived().TransformType(OldT); |
| 3829 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3830 | return SemaRef.ExprError(); |
| 3831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3833 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3834 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3835 | if (SubExpr.isInvalid()) |
| 3836 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3838 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3839 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3840 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | return SemaRef.Owned(E->Retain()); |
| 3842 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3843 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3844 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | E->getRParenLoc(), |
| 3846 | move(SubExpr)); |
| 3847 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3850 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3851 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3852 | QualType T; |
| 3853 | { |
| 3854 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3855 | SourceLocation FakeTypeLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3857 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | T = getDerived().TransformType(E->getType()); |
| 3860 | if (T.isNull()) |
| 3861 | return SemaRef.ExprError(); |
| 3862 | } |
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 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3865 | if (Init.isInvalid()) |
| 3866 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | if (!getDerived().AlwaysRebuild() && |
| 3869 | T == E->getType() && |
| 3870 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3872 | |
| 3873 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3874 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3875 | move(Init)); |
| 3876 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3878 | template<typename Derived> |
| 3879 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3880 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3881 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3882 | if (Base.isInvalid()) |
| 3883 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3885 | if (!getDerived().AlwaysRebuild() && |
| 3886 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3887 | return SemaRef.Owned(E->Retain()); |
| 3888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3889 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3890 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3891 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3892 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3893 | E->getAccessorLoc(), |
| 3894 | E->getAccessor()); |
| 3895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3897 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3898 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3899 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3900 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3903 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3904 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3905 | if (Init.isInvalid()) |
| 3906 | return SemaRef.ExprError(); |
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 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3909 | Inits.push_back(Init.takeAs<Expr>()); |
| 3910 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3913 | return SemaRef.Owned(E->Retain()); |
| 3914 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3916 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3917 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3919 | template<typename Derived> |
| 3920 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3921 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3922 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3923 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3924 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3926 | if (Init.isInvalid()) |
| 3927 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3929 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3931 | bool ExprChanged = false; |
| 3932 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3933 | DEnd = E->designators_end(); |
| 3934 | D != DEnd; ++D) { |
| 3935 | if (D->isFieldDesignator()) { |
| 3936 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3937 | D->getDotLoc(), |
| 3938 | D->getFieldLoc())); |
| 3939 | continue; |
| 3940 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3941 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3942 | if (D->isArrayDesignator()) { |
| 3943 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3944 | if (Index.isInvalid()) |
| 3945 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3946 | |
| 3947 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3951 | ArrayExprs.push_back(Index.release()); |
| 3952 | continue; |
| 3953 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3954 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3955 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3957 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3958 | if (Start.isInvalid()) |
| 3959 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3961 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3962 | if (End.isInvalid()) |
| 3963 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3964 | |
| 3965 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3966 | End.get(), |
| 3967 | D->getLBracketLoc(), |
| 3968 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3969 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3971 | End.get() != E->getArrayRangeEnd(*D); |
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 | ArrayExprs.push_back(Start.release()); |
| 3974 | ArrayExprs.push_back(End.release()); |
| 3975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3977 | if (!getDerived().AlwaysRebuild() && |
| 3978 | Init.get() == E->getInit() && |
| 3979 | !ExprChanged) |
| 3980 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3981 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3982 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3983 | E->getEqualOrColonLoc(), |
| 3984 | E->usesGNUSyntax(), move(Init)); |
| 3985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3987 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3990 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3991 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3992 | |
| 3993 | // FIXME: Will we ever have proper type location here? Will we actually |
| 3994 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | QualType T = getDerived().TransformType(E->getType()); |
| 3996 | if (T.isNull()) |
| 3997 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3998 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | if (!getDerived().AlwaysRebuild() && |
| 4000 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | return SemaRef.Owned(E->Retain()); |
| 4002 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4008 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | // FIXME: Do we want the type as written? |
| 4010 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4011 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | { |
| 4013 | // FIXME: Source location isn't quite accurate. |
| 4014 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4015 | T = getDerived().TransformType(E->getType()); |
| 4016 | if (T.isNull()) |
| 4017 | return SemaRef.ExprError(); |
| 4018 | } |
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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4021 | if (SubExpr.isInvalid()) |
| 4022 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | if (!getDerived().AlwaysRebuild() && |
| 4025 | T == E->getType() && |
| 4026 | SubExpr.get() == E->getSubExpr()) |
| 4027 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4030 | T, E->getRParenLoc()); |
| 4031 | } |
| 4032 | |
| 4033 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4034 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4035 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4036 | bool ArgumentChanged = false; |
| 4037 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4038 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4039 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4040 | if (Init.isInvalid()) |
| 4041 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4044 | Inits.push_back(Init.takeAs<Expr>()); |
| 4045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4047 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4048 | move_arg(Inits), |
| 4049 | E->getRParenLoc()); |
| 4050 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4052 | /// \brief Transform an address-of-label expression. |
| 4053 | /// |
| 4054 | /// By default, the transformation of an address-of-label expression always |
| 4055 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4056 | /// the corresponding label statement by semantic analysis. |
| 4057 | template<typename Derived> |
| 4058 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4059 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4060 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4061 | E->getLabel()); |
| 4062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
| 4064 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4065 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4066 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4067 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4068 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4069 | if (SubStmt.isInvalid()) |
| 4070 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4071 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4072 | if (!getDerived().AlwaysRebuild() && |
| 4073 | SubStmt.get() == E->getSubStmt()) |
| 4074 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | |
| 4076 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | move(SubStmt), |
| 4078 | E->getRParenLoc()); |
| 4079 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4081 | template<typename Derived> |
| 4082 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4083 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | QualType T1, T2; |
| 4085 | { |
| 4086 | // FIXME: Source location isn't quite accurate. |
| 4087 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
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 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4090 | if (T1.isNull()) |
| 4091 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4094 | if (T2.isNull()) |
| 4095 | return SemaRef.ExprError(); |
| 4096 | } |
| 4097 | |
| 4098 | if (!getDerived().AlwaysRebuild() && |
| 4099 | T1 == E->getArgType1() && |
| 4100 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4101 | return SemaRef.Owned(E->Retain()); |
| 4102 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4103 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4104 | T1, T2, E->getRParenLoc()); |
| 4105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4106 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | template<typename Derived> |
| 4108 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4109 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4111 | if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS()); |
| 4115 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4119 | if (RHS.isInvalid()) |
| 4120 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4122 | if (!getDerived().AlwaysRebuild() && |
| 4123 | Cond.get() == E->getCond() && |
| 4124 | LHS.get() == E->getLHS() && |
| 4125 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | return SemaRef.Owned(E->Retain()); |
| 4127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4129 | move(Cond), move(LHS), move(RHS), |
| 4130 | E->getRParenLoc()); |
| 4131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4134 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4135 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | template<typename Derived> |
| 4140 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4141 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4142 | switch (E->getOperator()) { |
| 4143 | case OO_New: |
| 4144 | case OO_Delete: |
| 4145 | case OO_Array_New: |
| 4146 | case OO_Array_Delete: |
| 4147 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4148 | return SemaRef.ExprError(); |
| 4149 | |
| 4150 | case OO_Call: { |
| 4151 | // This is a call to an object's operator(). |
| 4152 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4153 | |
| 4154 | // Transform the object itself. |
| 4155 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4156 | if (Object.isInvalid()) |
| 4157 | return SemaRef.ExprError(); |
| 4158 | |
| 4159 | // FIXME: Poor location information |
| 4160 | SourceLocation FakeLParenLoc |
| 4161 | = SemaRef.PP.getLocForEndOfToken( |
| 4162 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4163 | |
| 4164 | // Transform the call arguments. |
| 4165 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4166 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4167 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4168 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4169 | break; |
| 4170 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4171 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4172 | if (Arg.isInvalid()) |
| 4173 | return SemaRef.ExprError(); |
| 4174 | |
| 4175 | // FIXME: Poor source location information. |
| 4176 | SourceLocation FakeCommaLoc |
| 4177 | = SemaRef.PP.getLocForEndOfToken( |
| 4178 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4179 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4180 | Args.push_back(Arg.release()); |
| 4181 | } |
| 4182 | |
| 4183 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4184 | move_arg(Args), |
| 4185 | FakeCommaLocs.data(), |
| 4186 | E->getLocEnd()); |
| 4187 | } |
| 4188 | |
| 4189 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4190 | case OO_##Name: |
| 4191 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4192 | #include "clang/Basic/OperatorKinds.def" |
| 4193 | case OO_Subscript: |
| 4194 | // Handled below. |
| 4195 | break; |
| 4196 | |
| 4197 | case OO_Conditional: |
| 4198 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4199 | return SemaRef.ExprError(); |
| 4200 | |
| 4201 | case OO_None: |
| 4202 | case NUM_OVERLOADED_OPERATORS: |
| 4203 | llvm_unreachable("not an overloaded operator?"); |
| 4204 | return SemaRef.ExprError(); |
| 4205 | } |
| 4206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4208 | if (Callee.isInvalid()) |
| 4209 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4210 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4211 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4212 | if (First.isInvalid()) |
| 4213 | return SemaRef.ExprError(); |
| 4214 | |
| 4215 | OwningExprResult Second(SemaRef); |
| 4216 | if (E->getNumArgs() == 2) { |
| 4217 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4218 | if (Second.isInvalid()) |
| 4219 | return SemaRef.ExprError(); |
| 4220 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | if (!getDerived().AlwaysRebuild() && |
| 4223 | Callee.get() == E->getCallee() && |
| 4224 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4226 | return SemaRef.Owned(E->Retain()); |
| 4227 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4228 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4229 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4231 | move(First), |
| 4232 | move(Second)); |
| 4233 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4234 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | template<typename Derived> |
| 4236 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4237 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4238 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4242 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4243 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4244 | TypeSourceInfo *OldT; |
| 4245 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | { |
| 4247 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4248 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4249 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4250 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4251 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4252 | OldT = E->getTypeInfoAsWritten(); |
| 4253 | NewT = getDerived().TransformType(OldT); |
| 4254 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | return SemaRef.ExprError(); |
| 4256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4258 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4259 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4260 | if (SubExpr.isInvalid()) |
| 4261 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4264 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4265 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | return SemaRef.Owned(E->Retain()); |
| 4267 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4268 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4269 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4270 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4271 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4272 | SourceLocation FakeRParenLoc |
| 4273 | = SemaRef.PP.getLocForEndOfToken( |
| 4274 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4275 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4276 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4277 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4278 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4279 | FakeRAngleLoc, |
| 4280 | FakeRAngleLoc, |
| 4281 | move(SubExpr), |
| 4282 | FakeRParenLoc); |
| 4283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | template<typename Derived> |
| 4286 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4287 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4288 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
| 4291 | template<typename Derived> |
| 4292 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4293 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4294 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | } |
| 4296 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4297 | template<typename Derived> |
| 4298 | Sema::OwningExprResult |
| 4299 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4300 | CXXReinterpretCastExpr *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 |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4306 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4307 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4308 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4309 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | template<typename Derived> |
| 4311 | Sema::OwningExprResult |
| 4312 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4313 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4314 | TypeSourceInfo *OldT; |
| 4315 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4316 | { |
| 4317 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4319 | OldT = E->getTypeInfoAsWritten(); |
| 4320 | NewT = getDerived().TransformType(OldT); |
| 4321 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4322 | return SemaRef.ExprError(); |
| 4323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4325 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4326 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4327 | if (SubExpr.isInvalid()) |
| 4328 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4330 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4331 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4332 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4333 | return SemaRef.Owned(E->Retain()); |
| 4334 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4335 | // FIXME: The end of the type's source range is wrong |
| 4336 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4337 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4338 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4340 | move(SubExpr), |
| 4341 | E->getRParenLoc()); |
| 4342 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4343 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4344 | template<typename Derived> |
| 4345 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4346 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4347 | if (E->isTypeOperand()) { |
| 4348 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4351 | if (T.isNull()) |
| 4352 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4354 | if (!getDerived().AlwaysRebuild() && |
| 4355 | T == E->getTypeOperand()) |
| 4356 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4359 | /*FIXME:*/E->getLocStart(), |
| 4360 | T, |
| 4361 | E->getLocEnd()); |
| 4362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4364 | // We don't know whether the expression is potentially evaluated until |
| 4365 | // after we perform semantic analysis, so the expression is potentially |
| 4366 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4367 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4368 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4371 | if (SubExpr.isInvalid()) |
| 4372 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | if (!getDerived().AlwaysRebuild() && |
| 4375 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4376 | return SemaRef.Owned(E->Retain()); |
| 4377 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4378 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4379 | /*FIXME:*/E->getLocStart(), |
| 4380 | move(SubExpr), |
| 4381 | E->getLocEnd()); |
| 4382 | } |
| 4383 | |
| 4384 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4386 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | template<typename Derived> |
| 4391 | Sema::OwningExprResult |
| 4392 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4393 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4395 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4397 | template<typename Derived> |
| 4398 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4399 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | QualType T = getDerived().TransformType(E->getType()); |
| 4403 | if (T.isNull()) |
| 4404 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | if (!getDerived().AlwaysRebuild() && |
| 4407 | T == E->getType()) |
| 4408 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4410 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4411 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | template<typename Derived> |
| 4414 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4415 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4416 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4417 | if (SubExpr.isInvalid()) |
| 4418 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4419 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4420 | if (!getDerived().AlwaysRebuild() && |
| 4421 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | |
| 4424 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4425 | } |
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 | template<typename Derived> |
| 4428 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4429 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4432 | if (!Param) |
| 4433 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | if (getDerived().AlwaysRebuild() && |
| 4436 | Param == E->getParam()) |
| 4437 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4439 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4442 | template<typename Derived> |
| 4443 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4444 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4445 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4446 | |
| 4447 | QualType T = getDerived().TransformType(E->getType()); |
| 4448 | if (T.isNull()) |
| 4449 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4450 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4451 | if (!getDerived().AlwaysRebuild() && |
| 4452 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4453 | return SemaRef.Owned(E->Retain()); |
| 4454 | |
| 4455 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4457 | T, |
| 4458 | E->getRParenLoc()); |
| 4459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4461 | template<typename Derived> |
| 4462 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4463 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4464 | // Transform the type that we're allocating |
| 4465 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4466 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4467 | if (AllocType.isNull()) |
| 4468 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | // Transform the size of the array we're allocating (if any). |
| 4471 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4472 | if (ArraySize.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 | // Transform the placement arguments (if any). |
| 4476 | bool ArgumentChanged = false; |
| 4477 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4478 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4479 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4480 | if (Arg.isInvalid()) |
| 4481 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4484 | PlacementArgs.push_back(Arg.take()); |
| 4485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4487 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4489 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4490 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4491 | if (Arg.isInvalid()) |
| 4492 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4494 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4495 | ConstructorArgs.push_back(Arg.take()); |
| 4496 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4497 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | if (!getDerived().AlwaysRebuild() && |
| 4499 | AllocType == E->getAllocatedType() && |
| 4500 | ArraySize.get() == E->getArraySize() && |
| 4501 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4502 | return SemaRef.Owned(E->Retain()); |
| 4503 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4504 | if (!ArraySize.get()) { |
| 4505 | // If no array size was specified, but the new expression was |
| 4506 | // instantiated with an array type (e.g., "new T" where T is |
| 4507 | // instantiated with "int[4]"), extract the outer bound from the |
| 4508 | // array type as our array size. We do this with constant and |
| 4509 | // dependently-sized array types. |
| 4510 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4511 | if (!ArrayT) { |
| 4512 | // Do nothing |
| 4513 | } else if (const ConstantArrayType *ConsArrayT |
| 4514 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4515 | ArraySize |
| 4516 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4517 | ConsArrayT->getSize(), |
| 4518 | SemaRef.Context.getSizeType(), |
| 4519 | /*FIXME:*/E->getLocStart())); |
| 4520 | AllocType = ConsArrayT->getElementType(); |
| 4521 | } else if (const DependentSizedArrayType *DepArrayT |
| 4522 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4523 | if (DepArrayT->getSizeExpr()) { |
| 4524 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4525 | AllocType = DepArrayT->getElementType(); |
| 4526 | } |
| 4527 | } |
| 4528 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4530 | E->isGlobalNew(), |
| 4531 | /*FIXME:*/E->getLocStart(), |
| 4532 | move_arg(PlacementArgs), |
| 4533 | /*FIXME:*/E->getLocStart(), |
| 4534 | E->isParenTypeId(), |
| 4535 | AllocType, |
| 4536 | /*FIXME:*/E->getLocStart(), |
| 4537 | /*FIXME:*/SourceRange(), |
| 4538 | move(ArraySize), |
| 4539 | /*FIXME:*/E->getLocStart(), |
| 4540 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4541 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4544 | template<typename Derived> |
| 4545 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4546 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4547 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4548 | if (Operand.isInvalid()) |
| 4549 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4551 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | Operand.get() == E->getArgument()) |
| 4553 | return SemaRef.Owned(E->Retain()); |
| 4554 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4556 | E->isGlobalDelete(), |
| 4557 | E->isArrayForm(), |
| 4558 | move(Operand)); |
| 4559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | template<typename Derived> |
| 4562 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4563 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4564 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4565 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4566 | if (Base.isInvalid()) |
| 4567 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4568 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4569 | NestedNameSpecifier *Qualifier |
| 4570 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4571 | E->getQualifierRange()); |
| 4572 | if (E->getQualifier() && !Qualifier) |
| 4573 | return SemaRef.ExprError(); |
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 | QualType DestroyedType; |
| 4576 | { |
| 4577 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4578 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4579 | if (DestroyedType.isNull()) |
| 4580 | return SemaRef.ExprError(); |
| 4581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4582 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4583 | if (!getDerived().AlwaysRebuild() && |
| 4584 | Base.get() == E->getBase() && |
| 4585 | Qualifier == E->getQualifier() && |
| 4586 | DestroyedType == E->getDestroyedType()) |
| 4587 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4589 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4590 | E->getOperatorLoc(), |
| 4591 | E->isArrow(), |
| 4592 | E->getDestroyedTypeLoc(), |
| 4593 | DestroyedType, |
| 4594 | Qualifier, |
| 4595 | E->getQualifierRange()); |
| 4596 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4597 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4598 | template<typename Derived> |
| 4599 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4600 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4601 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4602 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4603 | |
| 4604 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4605 | Sema::LookupOrdinaryName); |
| 4606 | |
| 4607 | // Transform all the decls. |
| 4608 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4609 | E = Old->decls_end(); I != E; ++I) { |
| 4610 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4611 | if (!InstD) { |
| 4612 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4613 | // This can happen because of dependent hiding. |
| 4614 | if (isa<UsingShadowDecl>(*I)) |
| 4615 | continue; |
| 4616 | else |
| 4617 | return SemaRef.ExprError(); |
| 4618 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4619 | |
| 4620 | // Expand using declarations. |
| 4621 | if (isa<UsingDecl>(InstD)) { |
| 4622 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4623 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4624 | E = UD->shadow_end(); I != E; ++I) |
| 4625 | R.addDecl(*I); |
| 4626 | continue; |
| 4627 | } |
| 4628 | |
| 4629 | R.addDecl(InstD); |
| 4630 | } |
| 4631 | |
| 4632 | // Resolve a kind, but don't do any further analysis. If it's |
| 4633 | // ambiguous, the callee needs to deal with it. |
| 4634 | R.resolveKind(); |
| 4635 | |
| 4636 | // Rebuild the nested-name qualifier, if present. |
| 4637 | CXXScopeSpec SS; |
| 4638 | NestedNameSpecifier *Qualifier = 0; |
| 4639 | if (Old->getQualifier()) { |
| 4640 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4641 | Old->getQualifierRange()); |
| 4642 | if (!Qualifier) |
| 4643 | return SemaRef.ExprError(); |
| 4644 | |
| 4645 | SS.setScopeRep(Qualifier); |
| 4646 | SS.setRange(Old->getQualifierRange()); |
| 4647 | } |
| 4648 | |
| 4649 | // If we have no template arguments, it's a normal declaration name. |
| 4650 | if (!Old->hasExplicitTemplateArgs()) |
| 4651 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4652 | |
| 4653 | // If we have template arguments, rebuild them, then rebuild the |
| 4654 | // templateid expression. |
| 4655 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4656 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4657 | TemplateArgumentLoc Loc; |
| 4658 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4659 | return SemaRef.ExprError(); |
| 4660 | TransArgs.addArgument(Loc); |
| 4661 | } |
| 4662 | |
| 4663 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4664 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4665 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4666 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4667 | template<typename Derived> |
| 4668 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4669 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4670 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4673 | if (T.isNull()) |
| 4674 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | if (!getDerived().AlwaysRebuild() && |
| 4677 | T == E->getQueriedType()) |
| 4678 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | // FIXME: Bad location information |
| 4681 | SourceLocation FakeLParenLoc |
| 4682 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | |
| 4684 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | E->getLocStart(), |
| 4686 | /*FIXME:*/FakeLParenLoc, |
| 4687 | T, |
| 4688 | E->getLocEnd()); |
| 4689 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4690 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4691 | template<typename Derived> |
| 4692 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4693 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4694 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4696 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4697 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4698 | if (!NNS) |
| 4699 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | |
| 4701 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4702 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4703 | if (!Name) |
| 4704 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4706 | if (!E->hasExplicitTemplateArgs()) { |
| 4707 | if (!getDerived().AlwaysRebuild() && |
| 4708 | NNS == E->getQualifier() && |
| 4709 | Name == E->getDeclName()) |
| 4710 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4711 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4712 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4713 | E->getQualifierRange(), |
| 4714 | Name, E->getLocation(), |
| 4715 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4716 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4717 | |
| 4718 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4720 | TemplateArgumentLoc Loc; |
| 4721 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4723 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4726 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4727 | E->getQualifierRange(), |
| 4728 | Name, E->getLocation(), |
| 4729 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | template<typename Derived> |
| 4733 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4734 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4735 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4736 | |
| 4737 | QualType T = getDerived().TransformType(E->getType()); |
| 4738 | if (T.isNull()) |
| 4739 | return SemaRef.ExprError(); |
| 4740 | |
| 4741 | CXXConstructorDecl *Constructor |
| 4742 | = cast_or_null<CXXConstructorDecl>( |
| 4743 | getDerived().TransformDecl(E->getConstructor())); |
| 4744 | if (!Constructor) |
| 4745 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | bool ArgumentChanged = false; |
| 4748 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | ArgEnd = E->arg_end(); |
| 4751 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4752 | if (getDerived().DropCallArgument(*Arg)) { |
| 4753 | ArgumentChanged = true; |
| 4754 | break; |
| 4755 | } |
| 4756 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4757 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4758 | if (TransArg.isInvalid()) |
| 4759 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4761 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4762 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4763 | } |
| 4764 | |
| 4765 | if (!getDerived().AlwaysRebuild() && |
| 4766 | T == E->getType() && |
| 4767 | Constructor == E->getConstructor() && |
| 4768 | !ArgumentChanged) |
| 4769 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4771 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4772 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | move_arg(Args)); |
| 4774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4775 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | /// \brief Transform a C++ temporary-binding expression. |
| 4777 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4778 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4779 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | template<typename Derived> |
| 4781 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4782 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4783 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4785 | |
| 4786 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | /// be destroyed after the expression is evaluated. |
| 4788 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4789 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4790 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | template<typename Derived> |
| 4792 | Sema::OwningExprResult |
| 4793 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4794 | CXXExprWithTemporaries *E) { |
| 4795 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4796 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4798 | template<typename Derived> |
| 4799 | Sema::OwningExprResult |
| 4800 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4801 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4802 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4803 | QualType T = getDerived().TransformType(E->getType()); |
| 4804 | if (T.isNull()) |
| 4805 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | CXXConstructorDecl *Constructor |
| 4808 | = cast_or_null<CXXConstructorDecl>( |
| 4809 | getDerived().TransformDecl(E->getConstructor())); |
| 4810 | if (!Constructor) |
| 4811 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4812 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4813 | bool ArgumentChanged = false; |
| 4814 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4815 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | ArgEnd = E->arg_end(); |
| 4818 | Arg != ArgEnd; ++Arg) { |
| 4819 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4820 | if (TransArg.isInvalid()) |
| 4821 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4823 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4824 | Args.push_back((Expr *)TransArg.release()); |
| 4825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4826 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4827 | if (!getDerived().AlwaysRebuild() && |
| 4828 | T == E->getType() && |
| 4829 | Constructor == E->getConstructor() && |
| 4830 | !ArgumentChanged) |
| 4831 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4833 | // FIXME: Bogus location information |
| 4834 | SourceLocation CommaLoc; |
| 4835 | if (Args.size() > 1) { |
| 4836 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4839 | } |
| 4840 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4841 | T, |
| 4842 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4843 | move_arg(Args), |
| 4844 | &CommaLoc, |
| 4845 | E->getLocEnd()); |
| 4846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4848 | template<typename Derived> |
| 4849 | Sema::OwningExprResult |
| 4850 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4851 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4852 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4853 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4854 | if (T.isNull()) |
| 4855 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4856 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4857 | bool ArgumentChanged = false; |
| 4858 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4859 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4860 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4861 | ArgEnd = E->arg_end(); |
| 4862 | Arg != ArgEnd; ++Arg) { |
| 4863 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4864 | if (TransArg.isInvalid()) |
| 4865 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4866 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4867 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4868 | FakeCommaLocs.push_back( |
| 4869 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4870 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4871 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4872 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4873 | if (!getDerived().AlwaysRebuild() && |
| 4874 | T == E->getTypeAsWritten() && |
| 4875 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4876 | return SemaRef.Owned(E->Retain()); |
| 4877 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | // FIXME: we're faking the locations of the commas |
| 4879 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4880 | T, |
| 4881 | E->getLParenLoc(), |
| 4882 | move_arg(Args), |
| 4883 | FakeCommaLocs.data(), |
| 4884 | E->getRParenLoc()); |
| 4885 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4886 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4887 | template<typename Derived> |
| 4888 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4889 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4890 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4891 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4892 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4893 | Expr *OldBase; |
| 4894 | QualType BaseType; |
| 4895 | QualType ObjectType; |
| 4896 | if (!E->isImplicitAccess()) { |
| 4897 | OldBase = E->getBase(); |
| 4898 | Base = getDerived().TransformExpr(OldBase); |
| 4899 | if (Base.isInvalid()) |
| 4900 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4902 | // Start the member reference and compute the object's type. |
| 4903 | Sema::TypeTy *ObjectTy = 0; |
| 4904 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4905 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4906 | E->isArrow()? tok::arrow : tok::period, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4907 | ObjectTy); |
| 4908 | if (Base.isInvalid()) |
| 4909 | return SemaRef.ExprError(); |
| 4910 | |
| 4911 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 4912 | BaseType = ((Expr*) Base.get())->getType(); |
| 4913 | } else { |
| 4914 | OldBase = 0; |
| 4915 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 4916 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 4917 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4918 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4919 | // Transform the first part of the nested-name-specifier that qualifies |
| 4920 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4921 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4922 | = getDerived().TransformFirstQualifierInScope( |
| 4923 | E->getFirstQualifierFoundInScope(), |
| 4924 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4925 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4926 | NestedNameSpecifier *Qualifier = 0; |
| 4927 | if (E->getQualifier()) { |
| 4928 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4929 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4930 | ObjectType, |
| 4931 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4932 | if (!Qualifier) |
| 4933 | return SemaRef.ExprError(); |
| 4934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | |
| 4936 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4937 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4938 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4939 | if (!Name) |
| 4940 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4942 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4943 | // This is a reference to a member without an explicitly-specified |
| 4944 | // template argument list. Optimize for this common case. |
| 4945 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4946 | Base.get() == OldBase && |
| 4947 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4948 | Qualifier == E->getQualifier() && |
| 4949 | Name == E->getMember() && |
| 4950 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4951 | return SemaRef.Owned(E->Retain()); |
| 4952 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4953 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4954 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4955 | E->isArrow(), |
| 4956 | E->getOperatorLoc(), |
| 4957 | Qualifier, |
| 4958 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4959 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4960 | Name, |
| 4961 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4962 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4965 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4966 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4967 | TemplateArgumentLoc Loc; |
| 4968 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4969 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4970 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4971 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4972 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4973 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4974 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4975 | E->isArrow(), |
| 4976 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4977 | Qualifier, |
| 4978 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4979 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4980 | Name, |
| 4981 | E->getMemberLoc(), |
| 4982 | &TransArgs); |
| 4983 | } |
| 4984 | |
| 4985 | template<typename Derived> |
| 4986 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4987 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4988 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4989 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4990 | QualType BaseType; |
| 4991 | if (!Old->isImplicitAccess()) { |
| 4992 | Base = getDerived().TransformExpr(Old->getBase()); |
| 4993 | if (Base.isInvalid()) |
| 4994 | return SemaRef.ExprError(); |
| 4995 | BaseType = ((Expr*) Base.get())->getType(); |
| 4996 | } else { |
| 4997 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 4998 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4999 | |
| 5000 | NestedNameSpecifier *Qualifier = 0; |
| 5001 | if (Old->getQualifier()) { |
| 5002 | Qualifier |
| 5003 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 5004 | Old->getQualifierRange()); |
| 5005 | if (Qualifier == 0) |
| 5006 | return SemaRef.ExprError(); |
| 5007 | } |
| 5008 | |
| 5009 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5010 | Sema::LookupOrdinaryName); |
| 5011 | |
| 5012 | // Transform all the decls. |
| 5013 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5014 | E = Old->decls_end(); I != E; ++I) { |
| 5015 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5016 | if (!InstD) { |
| 5017 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5018 | // This can happen because of dependent hiding. |
| 5019 | if (isa<UsingShadowDecl>(*I)) |
| 5020 | continue; |
| 5021 | else |
| 5022 | return SemaRef.ExprError(); |
| 5023 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5024 | |
| 5025 | // Expand using declarations. |
| 5026 | if (isa<UsingDecl>(InstD)) { |
| 5027 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5028 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5029 | E = UD->shadow_end(); I != E; ++I) |
| 5030 | R.addDecl(*I); |
| 5031 | continue; |
| 5032 | } |
| 5033 | |
| 5034 | R.addDecl(InstD); |
| 5035 | } |
| 5036 | |
| 5037 | R.resolveKind(); |
| 5038 | |
| 5039 | TemplateArgumentListInfo TransArgs; |
| 5040 | if (Old->hasExplicitTemplateArgs()) { |
| 5041 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5042 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5043 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5044 | TemplateArgumentLoc Loc; |
| 5045 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5046 | Loc)) |
| 5047 | return SemaRef.ExprError(); |
| 5048 | TransArgs.addArgument(Loc); |
| 5049 | } |
| 5050 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5051 | |
| 5052 | // FIXME: to do this check properly, we will need to preserve the |
| 5053 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5054 | // base (and therefore couldn't do the check) and a |
| 5055 | // nested-name-qualifier (and therefore could do the lookup). |
| 5056 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5057 | |
| 5058 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5059 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5060 | Old->getOperatorLoc(), |
| 5061 | Old->isArrow(), |
| 5062 | Qualifier, |
| 5063 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5064 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5065 | R, |
| 5066 | (Old->hasExplicitTemplateArgs() |
| 5067 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | template<typename Derived> |
| 5071 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5072 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5074 | } |
| 5075 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5076 | template<typename Derived> |
| 5077 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5078 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5079 | // FIXME: poor source location |
| 5080 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5081 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5082 | if (EncodedType.isNull()) |
| 5083 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5085 | if (!getDerived().AlwaysRebuild() && |
| 5086 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | |
| 5089 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5090 | EncodedType, |
| 5091 | E->getRParenLoc()); |
| 5092 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +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>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5097 | // FIXME: Implement this! |
| 5098 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5099 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | } |
| 5101 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5102 | template<typename Derived> |
| 5103 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5104 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5105 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5108 | template<typename Derived> |
| 5109 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5110 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5112 | = cast_or_null<ObjCProtocolDecl>( |
| 5113 | getDerived().TransformDecl(E->getProtocol())); |
| 5114 | if (!Protocol) |
| 5115 | return SemaRef.ExprError(); |
| 5116 | |
| 5117 | if (!getDerived().AlwaysRebuild() && |
| 5118 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5119 | return SemaRef.Owned(E->Retain()); |
| 5120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5122 | E->getAtLoc(), |
| 5123 | /*FIXME:*/E->getAtLoc(), |
| 5124 | /*FIXME:*/E->getAtLoc(), |
| 5125 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5126 | |
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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *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 |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5139 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5140 | // FIXME: Implement this! |
| 5141 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5142 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5145 | template<typename Derived> |
| 5146 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5147 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5148 | ObjCImplicitSetterGetterRefExpr *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>::TransformObjCSuperExpr(ObjCSuperExpr *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>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5165 | // FIXME: Implement this! |
| 5166 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5170 | template<typename Derived> |
| 5171 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5173 | bool ArgumentChanged = false; |
| 5174 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5175 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5176 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5177 | if (SubExpr.isInvalid()) |
| 5178 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5181 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5182 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5183 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | if (!getDerived().AlwaysRebuild() && |
| 5185 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | return SemaRef.Owned(E->Retain()); |
| 5187 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5189 | move_arg(SubExprs), |
| 5190 | E->getRParenLoc()); |
| 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>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5196 | // FIXME: Implement this! |
| 5197 | assert(false && "Cannot transform block 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 | } |
| 5200 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5201 | template<typename Derived> |
| 5202 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5203 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | // FIXME: Implement this! |
| 5205 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5206 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5207 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5209 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5210 | // Type reconstruction |
| 5211 | //===----------------------------------------------------------------------===// |
| 5212 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5214 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5215 | SourceLocation Star) { |
| 5216 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5217 | getDerived().getBaseEntity()); |
| 5218 | } |
| 5219 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5221 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5222 | SourceLocation Star) { |
| 5223 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5224 | getDerived().getBaseEntity()); |
| 5225 | } |
| 5226 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | template<typename Derived> |
| 5228 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5229 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5230 | bool WrittenAsLValue, |
| 5231 | SourceLocation Sigil) { |
| 5232 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5233 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5237 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5238 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5239 | QualType ClassType, |
| 5240 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5241 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5242 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5247 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5248 | SourceLocation Sigil) { |
| 5249 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5250 | getDerived().getBaseEntity()); |
| 5251 | } |
| 5252 | |
| 5253 | template<typename Derived> |
| 5254 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5255 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5256 | ArrayType::ArraySizeModifier SizeMod, |
| 5257 | const llvm::APInt *Size, |
| 5258 | Expr *SizeExpr, |
| 5259 | unsigned IndexTypeQuals, |
| 5260 | SourceRange BracketsRange) { |
| 5261 | if (SizeExpr || !Size) |
| 5262 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5263 | IndexTypeQuals, BracketsRange, |
| 5264 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5265 | |
| 5266 | QualType Types[] = { |
| 5267 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5268 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5269 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5270 | }; |
| 5271 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5272 | QualType SizeType; |
| 5273 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5274 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5275 | SizeType = Types[I]; |
| 5276 | break; |
| 5277 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5279 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5280 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5281 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5282 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5285 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5286 | QualType |
| 5287 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5288 | ArrayType::ArraySizeModifier SizeMod, |
| 5289 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5290 | unsigned IndexTypeQuals, |
| 5291 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5292 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5293 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5298 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5299 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5300 | unsigned IndexTypeQuals, |
| 5301 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5303 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5306 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5307 | QualType |
| 5308 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5309 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5310 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5311 | unsigned IndexTypeQuals, |
| 5312 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5313 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5314 | SizeExpr.takeAs<Expr>(), |
| 5315 | IndexTypeQuals, BracketsRange); |
| 5316 | } |
| 5317 | |
| 5318 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5319 | QualType |
| 5320 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5321 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5322 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5323 | unsigned IndexTypeQuals, |
| 5324 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5325 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5326 | SizeExpr.takeAs<Expr>(), |
| 5327 | IndexTypeQuals, BracketsRange); |
| 5328 | } |
| 5329 | |
| 5330 | template<typename Derived> |
| 5331 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5332 | unsigned NumElements) { |
| 5333 | // FIXME: semantic checking! |
| 5334 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5335 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5336 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5337 | template<typename Derived> |
| 5338 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5339 | unsigned NumElements, |
| 5340 | SourceLocation AttributeLoc) { |
| 5341 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5342 | NumElements, true); |
| 5343 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5345 | AttributeLoc); |
| 5346 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5347 | 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> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5351 | QualType |
| 5352 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5353 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5354 | SourceLocation AttributeLoc) { |
| 5355 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5356 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5358 | template<typename Derived> |
| 5359 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5360 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5361 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5362 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5363 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5365 | Quals, |
| 5366 | getDerived().getBaseLocation(), |
| 5367 | getDerived().getBaseEntity()); |
| 5368 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5369 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5370 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5371 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5372 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5373 | } |
| 5374 | |
| 5375 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5376 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5377 | assert(D && "no decl found"); |
| 5378 | if (D->isInvalidDecl()) return QualType(); |
| 5379 | |
| 5380 | TypeDecl *Ty; |
| 5381 | if (isa<UsingDecl>(D)) { |
| 5382 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5383 | assert(Using->isTypeName() && |
| 5384 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5385 | |
| 5386 | // A valid resolved using typename decl points to exactly one type decl. |
| 5387 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5388 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5389 | |
| 5390 | } else { |
| 5391 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5392 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5393 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5394 | } |
| 5395 | |
| 5396 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5397 | } |
| 5398 | |
| 5399 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5401 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5402 | } |
| 5403 | |
| 5404 | template<typename Derived> |
| 5405 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5406 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5407 | } |
| 5408 | |
| 5409 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5410 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5411 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5412 | } |
| 5413 | |
| 5414 | template<typename Derived> |
| 5415 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5416 | TemplateName Template, |
| 5417 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5418 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5419 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5420 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5421 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5422 | template<typename Derived> |
| 5423 | NestedNameSpecifier * |
| 5424 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5425 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5426 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5427 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5428 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5429 | CXXScopeSpec SS; |
| 5430 | // FIXME: The source location information is all wrong. |
| 5431 | SS.setRange(Range); |
| 5432 | SS.setScopeRep(Prefix); |
| 5433 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5435 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5436 | ObjectType, |
| 5437 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5438 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | template<typename Derived> |
| 5442 | NestedNameSpecifier * |
| 5443 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5444 | SourceRange Range, |
| 5445 | NamespaceDecl *NS) { |
| 5446 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5447 | } |
| 5448 | |
| 5449 | template<typename Derived> |
| 5450 | NestedNameSpecifier * |
| 5451 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5452 | SourceRange Range, |
| 5453 | bool TemplateKW, |
| 5454 | QualType T) { |
| 5455 | if (T->isDependentType() || T->isRecordType() || |
| 5456 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5457 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5458 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5459 | T.getTypePtr()); |
| 5460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5461 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5462 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5463 | return 0; |
| 5464 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5466 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5467 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5468 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5469 | bool TemplateKW, |
| 5470 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5471 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5472 | Template); |
| 5473 | } |
| 5474 | |
| 5475 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5477 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5478 | const IdentifierInfo &II, |
| 5479 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5480 | CXXScopeSpec SS; |
| 5481 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5482 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5483 | UnqualifiedId Name; |
| 5484 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5485 | return getSema().ActOnDependentTemplateName( |
| 5486 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5487 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5488 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5489 | ObjectType.getAsOpaquePtr(), |
| 5490 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5491 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5494 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5495 | TemplateName |
| 5496 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5497 | OverloadedOperatorKind Operator, |
| 5498 | QualType ObjectType) { |
| 5499 | CXXScopeSpec SS; |
| 5500 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5501 | SS.setScopeRep(Qualifier); |
| 5502 | UnqualifiedId Name; |
| 5503 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5504 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5505 | Operator, SymbolLocations); |
| 5506 | return getSema().ActOnDependentTemplateName( |
| 5507 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5508 | SS, |
| 5509 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5510 | ObjectType.getAsOpaquePtr(), |
| 5511 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5512 | .template getAsVal<TemplateName>(); |
| 5513 | } |
| 5514 | |
| 5515 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5516 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5517 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5518 | SourceLocation OpLoc, |
| 5519 | ExprArg Callee, |
| 5520 | ExprArg First, |
| 5521 | ExprArg Second) { |
| 5522 | Expr *FirstExpr = (Expr *)First.get(); |
| 5523 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5524 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5525 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5526 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5527 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5528 | if (Op == OO_Subscript) { |
| 5529 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5530 | !SecondExpr->getType()->isOverloadableType()) |
| 5531 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5532 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5533 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5534 | } else if (Op == OO_Arrow) { |
| 5535 | // -> is never a builtin operation. |
| 5536 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5537 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5538 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5539 | // The argument is not of overloadable type, so try to create a |
| 5540 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5541 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5542 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5543 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5544 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5545 | } |
| 5546 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5547 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5548 | !SecondExpr->getType()->isOverloadableType()) { |
| 5549 | // Neither of the arguments is an overloadable type, so try to |
| 5550 | // create a built-in binary operation. |
| 5551 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5552 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5553 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5554 | if (Result.isInvalid()) |
| 5555 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5557 | First.release(); |
| 5558 | Second.release(); |
| 5559 | return move(Result); |
| 5560 | } |
| 5561 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5562 | |
| 5563 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5564 | // used during overload resolution. |
| 5565 | Sema::FunctionSet Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5566 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5567 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5568 | assert(ULE->requiresADL()); |
| 5569 | |
| 5570 | // FIXME: Do we have to check |
| 5571 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5572 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5573 | E = ULE->decls_end(); I != E; ++I) |
| 5574 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5575 | } else { |
| 5576 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5577 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 5578 | } |
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 | // Add any functions found via argument-dependent lookup. |
| 5581 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5582 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | DeclarationName OpName |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5584 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | 644be85 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5585 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5586 | Functions); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5587 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5588 | // Create the overloaded operator invocation for unary operators. |
| 5589 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5590 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5592 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5593 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5595 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5596 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5597 | OpLoc, |
| 5598 | move(First), |
| 5599 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5600 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5601 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5602 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5603 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5604 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5605 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5606 | if (Result.isInvalid()) |
| 5607 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5609 | First.release(); |
| 5610 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5614 | } // end namespace clang |
| 5615 | |
| 5616 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |