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 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 779 | /// \brief Build a new inline asm statement. |
| 780 | /// |
| 781 | /// By default, performs semantic analysis to build the new statement. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
| 783 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 784 | bool IsSimple, |
| 785 | bool IsVolatile, |
| 786 | unsigned NumOutputs, |
| 787 | unsigned NumInputs, |
| 788 | const std::string *Names, |
| 789 | MultiExprArg Constraints, |
| 790 | MultiExprArg Exprs, |
| 791 | ExprArg AsmString, |
| 792 | MultiExprArg Clobbers, |
| 793 | SourceLocation RParenLoc, |
| 794 | bool MSAsm) { |
| 795 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 796 | NumInputs, Names, move(Constraints), |
| 797 | move(Exprs), move(AsmString), move(Clobbers), |
| 798 | RParenLoc, MSAsm); |
| 799 | } |
| 800 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | /// \brief Build a new C++ exception declaration. |
| 802 | /// |
| 803 | /// By default, performs semantic analysis to build the new decaration. |
| 804 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 805 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 806 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 807 | IdentifierInfo *Name, |
| 808 | SourceLocation Loc, |
| 809 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 810 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 811 | TypeRange); |
| 812 | } |
| 813 | |
| 814 | /// \brief Build a new C++ catch statement. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis to build the new statement. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
| 818 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 819 | VarDecl *ExceptionDecl, |
| 820 | StmtArg Handler) { |
| 821 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 823 | Handler.takeAs<Stmt>())); |
| 824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 826 | /// \brief Build a new C++ try statement. |
| 827 | /// |
| 828 | /// By default, performs semantic analysis to build the new statement. |
| 829 | /// Subclasses may override this routine to provide different behavior. |
| 830 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 831 | StmtArg TryBlock, |
| 832 | MultiStmtArg Handlers) { |
| 833 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 834 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 836 | /// \brief Build a new expression that references a declaration. |
| 837 | /// |
| 838 | /// By default, performs semantic analysis to build the new expression. |
| 839 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 840 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 841 | LookupResult &R, |
| 842 | bool RequiresADL) { |
| 843 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 844 | } |
| 845 | |
| 846 | |
| 847 | /// \brief Build a new expression that references a declaration. |
| 848 | /// |
| 849 | /// By default, performs semantic analysis to build the new expression. |
| 850 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 851 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 852 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 853 | ValueDecl *VD, SourceLocation Loc, |
| 854 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 855 | CXXScopeSpec SS; |
| 856 | SS.setScopeRep(Qualifier); |
| 857 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 858 | |
| 859 | // FIXME: loses template args. |
| 860 | |
| 861 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 864 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 865 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 866 | /// By default, performs semantic analysis to build the new expression. |
| 867 | /// Subclasses may override this routine to provide different behavior. |
| 868 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 869 | SourceLocation RParen) { |
| 870 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 871 | } |
| 872 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 873 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 874 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 875 | /// By default, performs semantic analysis to build the new expression. |
| 876 | /// Subclasses may override this routine to provide different behavior. |
| 877 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 878 | SourceLocation OperatorLoc, |
| 879 | bool isArrow, |
| 880 | SourceLocation DestroyedTypeLoc, |
| 881 | QualType DestroyedType, |
| 882 | NestedNameSpecifier *Qualifier, |
| 883 | SourceRange QualifierRange) { |
| 884 | CXXScopeSpec SS; |
| 885 | if (Qualifier) { |
| 886 | SS.setRange(QualifierRange); |
| 887 | SS.setScopeRep(Qualifier); |
| 888 | } |
| 889 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 890 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 891 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 893 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 894 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 896 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 897 | OperatorLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 898 | SS, /*FIXME: FirstQualifier*/ 0, |
| 899 | Name, DestroyedTypeLoc, |
| 900 | /*TemplateArgs*/ 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 903 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 904 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 905 | /// By default, performs semantic analysis to build the new expression. |
| 906 | /// Subclasses may override this routine to provide different behavior. |
| 907 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 908 | UnaryOperator::Opcode Opc, |
| 909 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 910 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 911 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 913 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 915 | /// By default, performs semantic analysis to build the new expression. |
| 916 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 917 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 918 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 919 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 920 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 923 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 924 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | /// By default, performs semantic analysis to build the new expression. |
| 927 | /// Subclasses may override this routine to provide different behavior. |
| 928 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 929 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 931 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 932 | OpLoc, isSizeOf, R); |
| 933 | if (Result.isInvalid()) |
| 934 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 936 | SubExpr.release(); |
| 937 | return move(Result); |
| 938 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 940 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 941 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 942 | /// By default, performs semantic analysis to build the new expression. |
| 943 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | SourceLocation LBracketLoc, |
| 946 | ExprArg RHS, |
| 947 | SourceLocation RBracketLoc) { |
| 948 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 949 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 950 | RBracketLoc); |
| 951 | } |
| 952 | |
| 953 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 955 | /// By default, performs semantic analysis to build the new expression. |
| 956 | /// Subclasses may override this routine to provide different behavior. |
| 957 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 958 | MultiExprArg Args, |
| 959 | SourceLocation *CommaLocs, |
| 960 | SourceLocation RParenLoc) { |
| 961 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 962 | move(Args), CommaLocs, RParenLoc); |
| 963 | } |
| 964 | |
| 965 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 967 | /// By default, performs semantic analysis to build the new expression. |
| 968 | /// Subclasses may override this routine to provide different behavior. |
| 969 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 971 | NestedNameSpecifier *Qualifier, |
| 972 | SourceRange QualifierRange, |
| 973 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 974 | ValueDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 975 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 976 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 977 | if (!Member->getDeclName()) { |
| 978 | // We have a reference to an unnamed field. |
| 979 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 981 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 982 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 983 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 984 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 986 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 987 | Member, MemberLoc, |
| 988 | cast<FieldDecl>(Member)->getType()); |
| 989 | return getSema().Owned(ME); |
| 990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 992 | CXXScopeSpec SS; |
| 993 | if (Qualifier) { |
| 994 | SS.setRange(QualifierRange); |
| 995 | SS.setScopeRep(Qualifier); |
| 996 | } |
| 997 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 998 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 999 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1000 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1001 | Sema::LookupMemberName); |
| 1002 | R.addDecl(Member); |
| 1003 | R.resolveKind(); |
| 1004 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1005 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1006 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1007 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1008 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1011 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1012 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1013 | /// By default, performs semantic analysis to build the new expression. |
| 1014 | /// Subclasses may override this routine to provide different behavior. |
| 1015 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1016 | BinaryOperator::Opcode Opc, |
| 1017 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1018 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1019 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1024 | /// By default, performs semantic analysis to build the new expression. |
| 1025 | /// Subclasses may override this routine to provide different behavior. |
| 1026 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1027 | SourceLocation QuestionLoc, |
| 1028 | ExprArg LHS, |
| 1029 | SourceLocation ColonLoc, |
| 1030 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1032 | move(LHS), move(RHS)); |
| 1033 | } |
| 1034 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | /// \brief Build a new C-style cast expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1038 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1039 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1040 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1041 | SourceLocation RParenLoc, |
| 1042 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1043 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1044 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// By default, performs semantic analysis to build the new expression. |
| 1050 | /// Subclasses may override this routine to provide different behavior. |
| 1051 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1052 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | SourceLocation RParenLoc, |
| 1054 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1055 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1056 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1059 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1061 | /// By default, performs semantic analysis to build the new expression. |
| 1062 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1064 | SourceLocation OpLoc, |
| 1065 | SourceLocation AccessorLoc, |
| 1066 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1067 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1068 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1069 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1070 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1071 | OpLoc, /*IsArrow*/ false, |
| 1072 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1073 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1074 | AccessorLoc, |
| 1075 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | } |
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 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1080 | /// By default, performs semantic analysis to build the new expression. |
| 1081 | /// Subclasses may override this routine to provide different behavior. |
| 1082 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1083 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1084 | SourceLocation RBraceLoc, |
| 1085 | QualType ResultTy) { |
| 1086 | OwningExprResult Result |
| 1087 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1088 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1089 | return move(Result); |
| 1090 | |
| 1091 | // Patch in the result type we were given, which may have been computed |
| 1092 | // when the initial InitListExpr was built. |
| 1093 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1094 | ILE->setType(ResultTy); |
| 1095 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1096 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1099 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | /// By default, performs semantic analysis to build the new expression. |
| 1101 | /// Subclasses may override this routine to provide different behavior. |
| 1102 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1103 | MultiExprArg ArrayExprs, |
| 1104 | SourceLocation EqualOrColonLoc, |
| 1105 | bool GNUSyntax, |
| 1106 | ExprArg Init) { |
| 1107 | OwningExprResult Result |
| 1108 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1109 | move(Init)); |
| 1110 | if (Result.isInvalid()) |
| 1111 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1113 | ArrayExprs.release(); |
| 1114 | return move(Result); |
| 1115 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1119 | /// By default, builds the implicit value initialization without performing |
| 1120 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1121 | /// different behavior. |
| 1122 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1123 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1124 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1125 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1126 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// By default, performs semantic analysis to build the new expression. |
| 1129 | /// Subclasses may override this routine to provide different behavior. |
| 1130 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1131 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1133 | RParenLoc); |
| 1134 | } |
| 1135 | |
| 1136 | /// \brief Build a new expression list in parentheses. |
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 RebuildParenListExpr(SourceLocation LParenLoc, |
| 1141 | MultiExprArg SubExprs, |
| 1142 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1143 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1144 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1145 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1147 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | /// |
| 1149 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1150 | /// rather than attempting to map the label statement itself. |
| 1151 | /// Subclasses may override this routine to provide different behavior. |
| 1152 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1153 | SourceLocation LabelLoc, |
| 1154 | LabelStmt *Label) { |
| 1155 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1160 | /// By default, performs semantic analysis to build the new expression. |
| 1161 | /// Subclasses may override this routine to provide different behavior. |
| 1162 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1163 | StmtArg SubStmt, |
| 1164 | SourceLocation RParenLoc) { |
| 1165 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1168 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1169 | /// |
| 1170 | /// By default, performs semantic analysis to build the new expression. |
| 1171 | /// Subclasses may override this routine to provide different behavior. |
| 1172 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1173 | QualType T1, QualType T2, |
| 1174 | SourceLocation RParenLoc) { |
| 1175 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1176 | T1.getAsOpaquePtr(), |
| 1177 | T2.getAsOpaquePtr(), |
| 1178 | RParenLoc); |
| 1179 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1181 | /// \brief Build a new __builtin_choose_expr expression. |
| 1182 | /// |
| 1183 | /// By default, performs semantic analysis to build the new expression. |
| 1184 | /// Subclasses may override this routine to provide different behavior. |
| 1185 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1186 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1187 | SourceLocation RParenLoc) { |
| 1188 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1189 | move(Cond), move(LHS), move(RHS), |
| 1190 | RParenLoc); |
| 1191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | /// \brief Build a new overloaded operator call expression. |
| 1194 | /// |
| 1195 | /// By default, performs semantic analysis to build the new expression. |
| 1196 | /// The semantic analysis provides the behavior of template instantiation, |
| 1197 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1200 | /// provide different behavior. |
| 1201 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1202 | SourceLocation OpLoc, |
| 1203 | ExprArg Callee, |
| 1204 | ExprArg First, |
| 1205 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | |
| 1207 | /// \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] | 1208 | /// reinterpret_cast. |
| 1209 | /// |
| 1210 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1212 | /// Subclasses may override this routine to provide different behavior. |
| 1213 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1214 | Stmt::StmtClass Class, |
| 1215 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1216 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | SourceLocation RAngleLoc, |
| 1218 | SourceLocation LParenLoc, |
| 1219 | ExprArg SubExpr, |
| 1220 | SourceLocation RParenLoc) { |
| 1221 | switch (Class) { |
| 1222 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1223 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | move(SubExpr), RParenLoc); |
| 1226 | |
| 1227 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1228 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1233 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | RAngleLoc, LParenLoc, |
| 1235 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1239 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | default: |
| 1244 | assert(false && "Invalid C++ named cast"); |
| 1245 | break; |
| 1246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | return getSema().ExprError(); |
| 1249 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1250 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1251 | /// \brief Build a new C++ static_cast expression. |
| 1252 | /// |
| 1253 | /// By default, performs semantic analysis to build the new expression. |
| 1254 | /// Subclasses may override this routine to provide different behavior. |
| 1255 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1256 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1257 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1258 | SourceLocation RAngleLoc, |
| 1259 | SourceLocation LParenLoc, |
| 1260 | ExprArg SubExpr, |
| 1261 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1262 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1263 | TInfo, move(SubExpr), |
| 1264 | SourceRange(LAngleLoc, RAngleLoc), |
| 1265 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | /// \brief Build a new C++ dynamic_cast expression. |
| 1269 | /// |
| 1270 | /// By default, performs semantic analysis to build the new expression. |
| 1271 | /// Subclasses may override this routine to provide different behavior. |
| 1272 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1273 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1274 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1275 | SourceLocation RAngleLoc, |
| 1276 | SourceLocation LParenLoc, |
| 1277 | ExprArg SubExpr, |
| 1278 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1279 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1280 | TInfo, move(SubExpr), |
| 1281 | SourceRange(LAngleLoc, RAngleLoc), |
| 1282 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1286 | /// |
| 1287 | /// By default, performs semantic analysis to build the new expression. |
| 1288 | /// Subclasses may override this routine to provide different behavior. |
| 1289 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1290 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1291 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1292 | SourceLocation RAngleLoc, |
| 1293 | SourceLocation LParenLoc, |
| 1294 | ExprArg SubExpr, |
| 1295 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1296 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1297 | TInfo, move(SubExpr), |
| 1298 | SourceRange(LAngleLoc, RAngleLoc), |
| 1299 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | /// \brief Build a new C++ const_cast expression. |
| 1303 | /// |
| 1304 | /// By default, performs semantic analysis to build the new expression. |
| 1305 | /// Subclasses may override this routine to provide different behavior. |
| 1306 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1307 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1308 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | SourceLocation RAngleLoc, |
| 1310 | SourceLocation LParenLoc, |
| 1311 | ExprArg SubExpr, |
| 1312 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1313 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1314 | TInfo, move(SubExpr), |
| 1315 | SourceRange(LAngleLoc, RAngleLoc), |
| 1316 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1317 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | /// \brief Build a new C++ functional-style cast expression. |
| 1320 | /// |
| 1321 | /// By default, performs semantic analysis to build the new expression. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
| 1323 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1324 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1325 | SourceLocation LParenLoc, |
| 1326 | ExprArg SubExpr, |
| 1327 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1328 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1330 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1332 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | RParenLoc); |
| 1335 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1336 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | /// \brief Build a new C++ typeid(type) expression. |
| 1338 | /// |
| 1339 | /// By default, performs semantic analysis to build the new expression. |
| 1340 | /// Subclasses may override this routine to provide different behavior. |
| 1341 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1342 | SourceLocation LParenLoc, |
| 1343 | QualType T, |
| 1344 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1345 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1346 | T.getAsOpaquePtr(), RParenLoc); |
| 1347 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | /// \brief Build a new C++ typeid(expr) expression. |
| 1350 | /// |
| 1351 | /// By default, performs semantic analysis to build the new expression. |
| 1352 | /// Subclasses may override this routine to provide different behavior. |
| 1353 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1354 | SourceLocation LParenLoc, |
| 1355 | ExprArg Operand, |
| 1356 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1359 | RParenLoc); |
| 1360 | if (Result.isInvalid()) |
| 1361 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1364 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1367 | /// \brief Build a new C++ "this" expression. |
| 1368 | /// |
| 1369 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1370 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1371 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1373 | QualType ThisType, |
| 1374 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1376 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1377 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | /// \brief Build a new C++ throw expression. |
| 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new expression. |
| 1383 | /// Subclasses may override this routine to provide different behavior. |
| 1384 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1385 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1386 | } |
| 1387 | |
| 1388 | /// \brief Build a new C++ default-argument expression. |
| 1389 | /// |
| 1390 | /// By default, builds a new default-argument expression, which does not |
| 1391 | /// require any semantic analysis. Subclasses may override this routine to |
| 1392 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1393 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1394 | ParmVarDecl *Param) { |
| 1395 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1396 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | /// \brief Build a new C++ zero-initialization expression. |
| 1400 | /// |
| 1401 | /// By default, performs semantic analysis to build the new expression. |
| 1402 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | SourceLocation LParenLoc, |
| 1405 | QualType T, |
| 1406 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1408 | T.getAsOpaquePtr(), LParenLoc, |
| 1409 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | 0, RParenLoc); |
| 1411 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | /// \brief Build a new C++ "new" expression. |
| 1414 | /// |
| 1415 | /// By default, performs semantic analysis to build the new expression. |
| 1416 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | bool UseGlobal, |
| 1419 | SourceLocation PlacementLParen, |
| 1420 | MultiExprArg PlacementArgs, |
| 1421 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | QualType AllocType, |
| 1424 | SourceLocation TypeLoc, |
| 1425 | SourceRange TypeRange, |
| 1426 | ExprArg ArraySize, |
| 1427 | SourceLocation ConstructorLParen, |
| 1428 | MultiExprArg ConstructorArgs, |
| 1429 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | PlacementLParen, |
| 1432 | move(PlacementArgs), |
| 1433 | PlacementRParen, |
| 1434 | ParenTypeId, |
| 1435 | AllocType, |
| 1436 | TypeLoc, |
| 1437 | TypeRange, |
| 1438 | move(ArraySize), |
| 1439 | ConstructorLParen, |
| 1440 | move(ConstructorArgs), |
| 1441 | ConstructorRParen); |
| 1442 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1444 | /// \brief Build a new C++ "delete" expression. |
| 1445 | /// |
| 1446 | /// By default, performs semantic analysis to build the new expression. |
| 1447 | /// Subclasses may override this routine to provide different behavior. |
| 1448 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1449 | bool IsGlobalDelete, |
| 1450 | bool IsArrayForm, |
| 1451 | ExprArg Operand) { |
| 1452 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1453 | move(Operand)); |
| 1454 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | /// \brief Build a new unary type trait expression. |
| 1457 | /// |
| 1458 | /// By default, performs semantic analysis to build the new expression. |
| 1459 | /// Subclasses may override this routine to provide different behavior. |
| 1460 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1461 | SourceLocation StartLoc, |
| 1462 | SourceLocation LParenLoc, |
| 1463 | QualType T, |
| 1464 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1465 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | T.getAsOpaquePtr(), RParenLoc); |
| 1467 | } |
| 1468 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1469 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | /// expression. |
| 1471 | /// |
| 1472 | /// By default, performs semantic analysis to build the new expression. |
| 1473 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1474 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | SourceRange QualifierRange, |
| 1476 | DeclarationName Name, |
| 1477 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1478 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1479 | CXXScopeSpec SS; |
| 1480 | SS.setRange(QualifierRange); |
| 1481 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (TemplateArgs) |
| 1484 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1485 | *TemplateArgs); |
| 1486 | |
| 1487 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /// \brief Build a new template-id expression. |
| 1491 | /// |
| 1492 | /// By default, performs semantic analysis to build the new expression. |
| 1493 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1494 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1495 | LookupResult &R, |
| 1496 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1497 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1498 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /// \brief Build a new object-construction expression. |
| 1502 | /// |
| 1503 | /// By default, performs semantic analysis to build the new expression. |
| 1504 | /// Subclasses may override this routine to provide different behavior. |
| 1505 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1506 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | CXXConstructorDecl *Constructor, |
| 1508 | bool IsElidable, |
| 1509 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1510 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1511 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1512 | ConvertedArgs)) |
| 1513 | return getSema().ExprError(); |
| 1514 | |
| 1515 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1516 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /// \brief Build a new object-construction expression. |
| 1520 | /// |
| 1521 | /// By default, performs semantic analysis to build the new expression. |
| 1522 | /// Subclasses may override this routine to provide different behavior. |
| 1523 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1524 | QualType T, |
| 1525 | SourceLocation LParenLoc, |
| 1526 | MultiExprArg Args, |
| 1527 | SourceLocation *Commas, |
| 1528 | SourceLocation RParenLoc) { |
| 1529 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1530 | T.getAsOpaquePtr(), |
| 1531 | LParenLoc, |
| 1532 | move(Args), |
| 1533 | Commas, |
| 1534 | RParenLoc); |
| 1535 | } |
| 1536 | |
| 1537 | /// \brief Build a new object-construction expression. |
| 1538 | /// |
| 1539 | /// By default, performs semantic analysis to build the new expression. |
| 1540 | /// Subclasses may override this routine to provide different behavior. |
| 1541 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1542 | QualType T, |
| 1543 | SourceLocation LParenLoc, |
| 1544 | MultiExprArg Args, |
| 1545 | SourceLocation *Commas, |
| 1546 | SourceLocation RParenLoc) { |
| 1547 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1548 | /*FIXME*/LParenLoc), |
| 1549 | T.getAsOpaquePtr(), |
| 1550 | LParenLoc, |
| 1551 | move(Args), |
| 1552 | Commas, |
| 1553 | RParenLoc); |
| 1554 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1555 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1556 | /// \brief Build a new member reference expression. |
| 1557 | /// |
| 1558 | /// By default, performs semantic analysis to build the new expression. |
| 1559 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1560 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1561 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1562 | bool IsArrow, |
| 1563 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1564 | NestedNameSpecifier *Qualifier, |
| 1565 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1566 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1567 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1568 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1569 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1570 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1571 | SS.setRange(QualifierRange); |
| 1572 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1574 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1575 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1576 | SS, FirstQualifierInScope, |
| 1577 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1580 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1581 | /// |
| 1582 | /// By default, performs semantic analysis to build the new expression. |
| 1583 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1584 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1585 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1586 | SourceLocation OperatorLoc, |
| 1587 | bool IsArrow, |
| 1588 | NestedNameSpecifier *Qualifier, |
| 1589 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1590 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1591 | LookupResult &R, |
| 1592 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1593 | CXXScopeSpec SS; |
| 1594 | SS.setRange(QualifierRange); |
| 1595 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1596 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1597 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1598 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1599 | SS, FirstQualifierInScope, |
| 1600 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1601 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1602 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | /// \brief Build a new Objective-C @encode expression. |
| 1604 | /// |
| 1605 | /// By default, performs semantic analysis to build the new expression. |
| 1606 | /// Subclasses may override this routine to provide different behavior. |
| 1607 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1608 | QualType T, |
| 1609 | SourceLocation RParenLoc) { |
| 1610 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1611 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1612 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1613 | |
| 1614 | /// \brief Build a new Objective-C protocol expression. |
| 1615 | /// |
| 1616 | /// By default, performs semantic analysis to build the new expression. |
| 1617 | /// Subclasses may override this routine to provide different behavior. |
| 1618 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1619 | SourceLocation AtLoc, |
| 1620 | SourceLocation ProtoLoc, |
| 1621 | SourceLocation LParenLoc, |
| 1622 | SourceLocation RParenLoc) { |
| 1623 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1624 | Protocol->getIdentifier(), |
| 1625 | AtLoc, |
| 1626 | ProtoLoc, |
| 1627 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1628 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1630 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1631 | /// \brief Build a new shuffle vector expression. |
| 1632 | /// |
| 1633 | /// By default, performs semantic analysis to build the new expression. |
| 1634 | /// Subclasses may override this routine to provide different behavior. |
| 1635 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1636 | MultiExprArg SubExprs, |
| 1637 | SourceLocation RParenLoc) { |
| 1638 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1639 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1641 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1642 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1643 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | // Build a reference to the __builtin_shufflevector builtin |
| 1646 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1649 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | |
| 1652 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | unsigned NumSubExprs = SubExprs.size(); |
| 1654 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1655 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1656 | Subs, NumSubExprs, |
| 1657 | Builtin->getResultType(), |
| 1658 | RParenLoc); |
| 1659 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | // Type-check the __builtin_shufflevector expression. |
| 1662 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1663 | if (Result.isInvalid()) |
| 1664 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1667 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1668 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1669 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1670 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1671 | template<typename Derived> |
| 1672 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1673 | if (!S) |
| 1674 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1676 | switch (S->getStmtClass()) { |
| 1677 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1678 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1679 | // Transform individual statement nodes |
| 1680 | #define STMT(Node, Parent) \ |
| 1681 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1682 | #define EXPR(Node, Parent) |
| 1683 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1685 | // Transform expressions by calling TransformExpr. |
| 1686 | #define STMT(Node, Parent) |
| 1687 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1688 | #include "clang/AST/StmtNodes.def" |
| 1689 | { |
| 1690 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1691 | if (E.isInvalid()) |
| 1692 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1694 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1698 | return SemaRef.Owned(S->Retain()); |
| 1699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1700 | |
| 1701 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1702 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1703 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | if (!E) |
| 1705 | return SemaRef.Owned(E); |
| 1706 | |
| 1707 | switch (E->getStmtClass()) { |
| 1708 | case Stmt::NoStmtClass: break; |
| 1709 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1710 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1711 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1715 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1719 | NestedNameSpecifier * |
| 1720 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1721 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1722 | QualType ObjectType, |
| 1723 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1724 | if (!NNS) |
| 1725 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1726 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1727 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1728 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1729 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1731 | ObjectType, |
| 1732 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1733 | if (!Prefix) |
| 1734 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
| 1736 | // 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] | 1737 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1738 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1739 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1740 | } |
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 | switch (NNS->getKind()) { |
| 1743 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1745 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1746 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1747 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1748 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
| 1750 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1751 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1752 | ObjectType, |
| 1753 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1755 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1757 | = cast_or_null<NamespaceDecl>( |
| 1758 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1760 | Prefix == NNS->getPrefix() && |
| 1761 | NS == NNS->getAsNamespace()) |
| 1762 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1764 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1765 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | case NestedNameSpecifier::Global: |
| 1768 | // There is no meaningful transformation that one could perform on the |
| 1769 | // global scope. |
| 1770 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1772 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1773 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1774 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1775 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1776 | if (T.isNull()) |
| 1777 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1779 | if (!getDerived().AlwaysRebuild() && |
| 1780 | Prefix == NNS->getPrefix() && |
| 1781 | T == QualType(NNS->getAsType(), 0)) |
| 1782 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
| 1784 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1785 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1786 | T); |
| 1787 | } |
| 1788 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1789 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1790 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1791 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1795 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1796 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1797 | SourceLocation Loc, |
| 1798 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1799 | if (!Name) |
| 1800 | return Name; |
| 1801 | |
| 1802 | switch (Name.getNameKind()) { |
| 1803 | case DeclarationName::Identifier: |
| 1804 | case DeclarationName::ObjCZeroArgSelector: |
| 1805 | case DeclarationName::ObjCOneArgSelector: |
| 1806 | case DeclarationName::ObjCMultiArgSelector: |
| 1807 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1808 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1809 | case DeclarationName::CXXUsingDirective: |
| 1810 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1812 | case DeclarationName::CXXConstructorName: |
| 1813 | case DeclarationName::CXXDestructorName: |
| 1814 | case DeclarationName::CXXConversionFunctionName: { |
| 1815 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1816 | QualType T; |
| 1817 | if (!ObjectType.isNull() && |
| 1818 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1819 | TemplateSpecializationType *SpecType |
| 1820 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1821 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1822 | } else |
| 1823 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1824 | if (T.isNull()) |
| 1825 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1827 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1828 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1829 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1830 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1833 | return DeclarationName(); |
| 1834 | } |
| 1835 | |
| 1836 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1838 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1839 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1840 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1842 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1843 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1844 | if (!NNS) |
| 1845 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1846 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1847 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1848 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1849 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1850 | if (!TransTemplate) |
| 1851 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | if (!getDerived().AlwaysRebuild() && |
| 1854 | NNS == QTN->getQualifier() && |
| 1855 | TransTemplate == Template) |
| 1856 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1858 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1859 | TransTemplate); |
| 1860 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1862 | // These should be getting filtered out before they make it into the AST. |
| 1863 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1864 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1866 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1869 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1870 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1871 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1873 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1874 | NNS == DTN->getQualifier() && |
| 1875 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1876 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1878 | if (DTN->isIdentifier()) |
| 1879 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1880 | ObjectType); |
| 1881 | |
| 1882 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1883 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1884 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1885 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1886 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1888 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1889 | if (!TransTemplate) |
| 1890 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1892 | if (!getDerived().AlwaysRebuild() && |
| 1893 | TransTemplate == Template) |
| 1894 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1895 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1896 | return TemplateName(TransTemplate); |
| 1897 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1899 | // These should be getting filtered out before they reach the AST. |
| 1900 | assert(false && "overloaded function decl survived to here"); |
| 1901 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1905 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1906 | const TemplateArgument &Arg, |
| 1907 | TemplateArgumentLoc &Output) { |
| 1908 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1909 | switch (Arg.getKind()) { |
| 1910 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1911 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1912 | break; |
| 1913 | |
| 1914 | case TemplateArgument::Type: |
| 1915 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1916 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1917 | |
| 1918 | break; |
| 1919 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1920 | case TemplateArgument::Template: |
| 1921 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1922 | break; |
| 1923 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1924 | case TemplateArgument::Expression: |
| 1925 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1926 | break; |
| 1927 | |
| 1928 | case TemplateArgument::Declaration: |
| 1929 | case TemplateArgument::Integral: |
| 1930 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1931 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1932 | break; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | template<typename Derived> |
| 1937 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1938 | const TemplateArgumentLoc &Input, |
| 1939 | TemplateArgumentLoc &Output) { |
| 1940 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1941 | switch (Arg.getKind()) { |
| 1942 | case TemplateArgument::Null: |
| 1943 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1944 | Output = Input; |
| 1945 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1946 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1947 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1948 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1949 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1950 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1951 | |
| 1952 | DI = getDerived().TransformType(DI); |
| 1953 | if (!DI) return true; |
| 1954 | |
| 1955 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1956 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1957 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1959 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1960 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1961 | DeclarationName Name; |
| 1962 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1963 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1964 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1965 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1966 | if (!D) return true; |
| 1967 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1968 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1969 | if (SourceExpr) { |
| 1970 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1971 | Action::Unevaluated); |
| 1972 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1973 | if (E.isInvalid()) |
| 1974 | SourceExpr = NULL; |
| 1975 | else { |
| 1976 | SourceExpr = E.takeAs<Expr>(); |
| 1977 | SourceExpr->Retain(); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1982 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1983 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1984 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1985 | case TemplateArgument::Template: { |
| 1986 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1987 | TemplateName Template |
| 1988 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1989 | if (Template.isNull()) |
| 1990 | return true; |
| 1991 | |
| 1992 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1993 | Input.getTemplateQualifierRange(), |
| 1994 | Input.getTemplateNameLoc()); |
| 1995 | return false; |
| 1996 | } |
| 1997 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1998 | case TemplateArgument::Expression: { |
| 1999 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2000 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2001 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2002 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2003 | Expr *InputExpr = Input.getSourceExpression(); |
| 2004 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2005 | |
| 2006 | Sema::OwningExprResult E |
| 2007 | = getDerived().TransformExpr(InputExpr); |
| 2008 | if (E.isInvalid()) return true; |
| 2009 | |
| 2010 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2011 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2012 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2013 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2016 | case TemplateArgument::Pack: { |
| 2017 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2018 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2019 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2020 | AEnd = Arg.pack_end(); |
| 2021 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2023 | // FIXME: preserve source information here when we start |
| 2024 | // caring about parameter packs. |
| 2025 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2026 | TemplateArgumentLoc InputArg; |
| 2027 | TemplateArgumentLoc OutputArg; |
| 2028 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2029 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2030 | return true; |
| 2031 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2032 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2033 | } |
| 2034 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2036 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2037 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2038 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2039 | } |
| 2040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2041 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2042 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2043 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2046 | //===----------------------------------------------------------------------===// |
| 2047 | // Type transformation |
| 2048 | //===----------------------------------------------------------------------===// |
| 2049 | |
| 2050 | template<typename Derived> |
| 2051 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2052 | if (getDerived().AlreadyTransformed(T)) |
| 2053 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2054 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2055 | // Temporary workaround. All of these transformations should |
| 2056 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2057 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2058 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2059 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2060 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2061 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2062 | if (!NewDI) |
| 2063 | return QualType(); |
| 2064 | |
| 2065 | return NewDI->getType(); |
| 2066 | } |
| 2067 | |
| 2068 | template<typename Derived> |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2069 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2070 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2071 | return DI; |
| 2072 | |
| 2073 | TypeLocBuilder TLB; |
| 2074 | |
| 2075 | TypeLoc TL = DI->getTypeLoc(); |
| 2076 | TLB.reserve(TL.getFullDataSize()); |
| 2077 | |
| 2078 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2079 | if (Result.isNull()) |
| 2080 | return 0; |
| 2081 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2082 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | template<typename Derived> |
| 2086 | QualType |
| 2087 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2088 | switch (T.getTypeLocClass()) { |
| 2089 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2090 | #define TYPELOC(CLASS, PARENT) \ |
| 2091 | case TypeLoc::CLASS: \ |
| 2092 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2093 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2094 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2095 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2096 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2097 | return QualType(); |
| 2098 | } |
| 2099 | |
| 2100 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2101 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2102 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2103 | /// types). This is the right thing for template instantiation, but |
| 2104 | /// probably not for other clients. |
| 2105 | template<typename Derived> |
| 2106 | QualType |
| 2107 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2108 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2109 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2110 | |
| 2111 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2112 | if (Result.isNull()) |
| 2113 | return QualType(); |
| 2114 | |
| 2115 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2116 | // FIXME: this is the right thing for template instantiation, but |
| 2117 | // probably not for other clients. |
| 2118 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2119 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2120 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2121 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2122 | |
| 2123 | TLB.push<QualifiedTypeLoc>(Result); |
| 2124 | |
| 2125 | // No location information to preserve. |
| 2126 | |
| 2127 | return Result; |
| 2128 | } |
| 2129 | |
| 2130 | template <class TyLoc> static inline |
| 2131 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2132 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2133 | NewT.setNameLoc(T.getNameLoc()); |
| 2134 | return T.getType(); |
| 2135 | } |
| 2136 | |
| 2137 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2138 | // the equivalent template version work. |
| 2139 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2140 | QualType PointeeType \ |
| 2141 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2142 | if (PointeeType.isNull()) \ |
| 2143 | return QualType(); \ |
| 2144 | \ |
| 2145 | QualType Result = TL.getType(); \ |
| 2146 | if (getDerived().AlwaysRebuild() || \ |
| 2147 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2148 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2149 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2150 | if (Result.isNull()) \ |
| 2151 | return QualType(); \ |
| 2152 | } \ |
| 2153 | \ |
| 2154 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2155 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2156 | \ |
| 2157 | return Result; \ |
| 2158 | } while(0) |
| 2159 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2160 | template<typename Derived> |
| 2161 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2162 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2163 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2164 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2165 | if (T.needsExtraLocalData()) |
| 2166 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2167 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2168 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2169 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2170 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2171 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2172 | ComplexTypeLoc T) { |
| 2173 | // FIXME: recurse? |
| 2174 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2177 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2178 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2179 | PointerTypeLoc TL) { |
| 2180 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2181 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2182 | |
| 2183 | template<typename Derived> |
| 2184 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2185 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2186 | BlockPointerTypeLoc TL) { |
| 2187 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2190 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2191 | /// don't care whether the type itself is an l-value type or an r-value |
| 2192 | /// type; we only care if the type was *written* as an l-value type |
| 2193 | /// or an r-value type. |
| 2194 | template<typename Derived> |
| 2195 | QualType |
| 2196 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2197 | ReferenceTypeLoc TL) { |
| 2198 | const ReferenceType *T = TL.getTypePtr(); |
| 2199 | |
| 2200 | // Note that this works with the pointee-as-written. |
| 2201 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2202 | if (PointeeType.isNull()) |
| 2203 | return QualType(); |
| 2204 | |
| 2205 | QualType Result = TL.getType(); |
| 2206 | if (getDerived().AlwaysRebuild() || |
| 2207 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2208 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2209 | T->isSpelledAsLValue(), |
| 2210 | TL.getSigilLoc()); |
| 2211 | if (Result.isNull()) |
| 2212 | return QualType(); |
| 2213 | } |
| 2214 | |
| 2215 | // r-value references can be rebuilt as l-value references. |
| 2216 | ReferenceTypeLoc NewTL; |
| 2217 | if (isa<LValueReferenceType>(Result)) |
| 2218 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2219 | else |
| 2220 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2221 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2222 | |
| 2223 | return Result; |
| 2224 | } |
| 2225 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2226 | template<typename Derived> |
| 2227 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2228 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2229 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2230 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | template<typename Derived> |
| 2234 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2235 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2236 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2237 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2238 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2239 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2240 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2241 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2242 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2243 | MemberPointerTypeLoc TL) { |
| 2244 | MemberPointerType *T = TL.getTypePtr(); |
| 2245 | |
| 2246 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2247 | if (PointeeType.isNull()) |
| 2248 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2249 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2250 | // TODO: preserve source information for this. |
| 2251 | QualType ClassType |
| 2252 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2253 | if (ClassType.isNull()) |
| 2254 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2256 | QualType Result = TL.getType(); |
| 2257 | if (getDerived().AlwaysRebuild() || |
| 2258 | PointeeType != T->getPointeeType() || |
| 2259 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2260 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2261 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2262 | if (Result.isNull()) |
| 2263 | return QualType(); |
| 2264 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2265 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2266 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2267 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2268 | |
| 2269 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2272 | template<typename Derived> |
| 2273 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2274 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2275 | ConstantArrayTypeLoc TL) { |
| 2276 | ConstantArrayType *T = TL.getTypePtr(); |
| 2277 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2278 | if (ElementType.isNull()) |
| 2279 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2280 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2281 | QualType Result = TL.getType(); |
| 2282 | if (getDerived().AlwaysRebuild() || |
| 2283 | ElementType != T->getElementType()) { |
| 2284 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2285 | T->getSizeModifier(), |
| 2286 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2287 | T->getIndexTypeCVRQualifiers(), |
| 2288 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2289 | if (Result.isNull()) |
| 2290 | return QualType(); |
| 2291 | } |
| 2292 | |
| 2293 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2294 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2295 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2296 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2297 | Expr *Size = TL.getSizeExpr(); |
| 2298 | if (Size) { |
| 2299 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2300 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2301 | } |
| 2302 | NewTL.setSizeExpr(Size); |
| 2303 | |
| 2304 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2306 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2307 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2308 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2309 | TypeLocBuilder &TLB, |
| 2310 | IncompleteArrayTypeLoc TL) { |
| 2311 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2312 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2313 | if (ElementType.isNull()) |
| 2314 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2315 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2316 | QualType Result = TL.getType(); |
| 2317 | if (getDerived().AlwaysRebuild() || |
| 2318 | ElementType != T->getElementType()) { |
| 2319 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2320 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2321 | T->getIndexTypeCVRQualifiers(), |
| 2322 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2323 | if (Result.isNull()) |
| 2324 | return QualType(); |
| 2325 | } |
| 2326 | |
| 2327 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2328 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2329 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2330 | NewTL.setSizeExpr(0); |
| 2331 | |
| 2332 | return Result; |
| 2333 | } |
| 2334 | |
| 2335 | template<typename Derived> |
| 2336 | QualType |
| 2337 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2338 | VariableArrayTypeLoc TL) { |
| 2339 | VariableArrayType *T = TL.getTypePtr(); |
| 2340 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2341 | if (ElementType.isNull()) |
| 2342 | return QualType(); |
| 2343 | |
| 2344 | // Array bounds are not potentially evaluated contexts |
| 2345 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2346 | |
| 2347 | Sema::OwningExprResult SizeResult |
| 2348 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2349 | if (SizeResult.isInvalid()) |
| 2350 | return QualType(); |
| 2351 | |
| 2352 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2353 | |
| 2354 | QualType Result = TL.getType(); |
| 2355 | if (getDerived().AlwaysRebuild() || |
| 2356 | ElementType != T->getElementType() || |
| 2357 | Size != T->getSizeExpr()) { |
| 2358 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2359 | T->getSizeModifier(), |
| 2360 | move(SizeResult), |
| 2361 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2362 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2363 | if (Result.isNull()) |
| 2364 | return QualType(); |
| 2365 | } |
| 2366 | else SizeResult.take(); |
| 2367 | |
| 2368 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2369 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2370 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2371 | NewTL.setSizeExpr(Size); |
| 2372 | |
| 2373 | return Result; |
| 2374 | } |
| 2375 | |
| 2376 | template<typename Derived> |
| 2377 | QualType |
| 2378 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2379 | DependentSizedArrayTypeLoc TL) { |
| 2380 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2381 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2382 | if (ElementType.isNull()) |
| 2383 | return QualType(); |
| 2384 | |
| 2385 | // Array bounds are not potentially evaluated contexts |
| 2386 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2387 | |
| 2388 | Sema::OwningExprResult SizeResult |
| 2389 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2390 | if (SizeResult.isInvalid()) |
| 2391 | return QualType(); |
| 2392 | |
| 2393 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2394 | |
| 2395 | QualType Result = TL.getType(); |
| 2396 | if (getDerived().AlwaysRebuild() || |
| 2397 | ElementType != T->getElementType() || |
| 2398 | Size != T->getSizeExpr()) { |
| 2399 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2400 | T->getSizeModifier(), |
| 2401 | move(SizeResult), |
| 2402 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2403 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2404 | if (Result.isNull()) |
| 2405 | return QualType(); |
| 2406 | } |
| 2407 | else SizeResult.take(); |
| 2408 | |
| 2409 | // We might have any sort of array type now, but fortunately they |
| 2410 | // all have the same location layout. |
| 2411 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2412 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2413 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2414 | NewTL.setSizeExpr(Size); |
| 2415 | |
| 2416 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2418 | |
| 2419 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2420 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2421 | TypeLocBuilder &TLB, |
| 2422 | DependentSizedExtVectorTypeLoc TL) { |
| 2423 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2424 | |
| 2425 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2426 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2427 | if (ElementType.isNull()) |
| 2428 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2429 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2430 | // Vector sizes are not potentially evaluated contexts |
| 2431 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2432 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2433 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2434 | if (Size.isInvalid()) |
| 2435 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2437 | QualType Result = TL.getType(); |
| 2438 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2439 | ElementType != T->getElementType() || |
| 2440 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2441 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2442 | move(Size), |
| 2443 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2444 | if (Result.isNull()) |
| 2445 | return QualType(); |
| 2446 | } |
| 2447 | else Size.take(); |
| 2448 | |
| 2449 | // Result might be dependent or not. |
| 2450 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2451 | DependentSizedExtVectorTypeLoc NewTL |
| 2452 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2453 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2454 | } else { |
| 2455 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2456 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2457 | } |
| 2458 | |
| 2459 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2461 | |
| 2462 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2464 | VectorTypeLoc TL) { |
| 2465 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2466 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2467 | if (ElementType.isNull()) |
| 2468 | return QualType(); |
| 2469 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2470 | QualType Result = TL.getType(); |
| 2471 | if (getDerived().AlwaysRebuild() || |
| 2472 | ElementType != T->getElementType()) { |
| 2473 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2474 | if (Result.isNull()) |
| 2475 | return QualType(); |
| 2476 | } |
| 2477 | |
| 2478 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2479 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2480 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2481 | return Result; |
| 2482 | } |
| 2483 | |
| 2484 | template<typename Derived> |
| 2485 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2486 | ExtVectorTypeLoc TL) { |
| 2487 | VectorType *T = TL.getTypePtr(); |
| 2488 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2489 | if (ElementType.isNull()) |
| 2490 | return QualType(); |
| 2491 | |
| 2492 | QualType Result = TL.getType(); |
| 2493 | if (getDerived().AlwaysRebuild() || |
| 2494 | ElementType != T->getElementType()) { |
| 2495 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2496 | T->getNumElements(), |
| 2497 | /*FIXME*/ SourceLocation()); |
| 2498 | if (Result.isNull()) |
| 2499 | return QualType(); |
| 2500 | } |
| 2501 | |
| 2502 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2503 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2504 | |
| 2505 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2506 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2507 | |
| 2508 | template<typename Derived> |
| 2509 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2510 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2511 | FunctionProtoTypeLoc TL) { |
| 2512 | FunctionProtoType *T = TL.getTypePtr(); |
| 2513 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2514 | if (ResultType.isNull()) |
| 2515 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2516 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2517 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2518 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2519 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2520 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2521 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2522 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2523 | QualType NewType; |
| 2524 | ParmVarDecl *NewParm; |
| 2525 | |
| 2526 | if (OldParm) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2527 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2528 | assert(OldDI->getType() == T->getArgType(i)); |
| 2529 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2530 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2531 | if (!NewDI) |
| 2532 | return QualType(); |
| 2533 | |
| 2534 | if (NewDI == OldDI) |
| 2535 | NewParm = OldParm; |
| 2536 | else |
| 2537 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2538 | OldParm->getDeclContext(), |
| 2539 | OldParm->getLocation(), |
| 2540 | OldParm->getIdentifier(), |
| 2541 | NewDI->getType(), |
| 2542 | NewDI, |
| 2543 | OldParm->getStorageClass(), |
| 2544 | /* DefArg */ NULL); |
| 2545 | NewType = NewParm->getType(); |
| 2546 | |
| 2547 | // Deal with the possibility that we don't have a parameter |
| 2548 | // declaration for this parameter. |
| 2549 | } else { |
| 2550 | NewParm = 0; |
| 2551 | |
| 2552 | QualType OldType = T->getArgType(i); |
| 2553 | NewType = getDerived().TransformType(OldType); |
| 2554 | if (NewType.isNull()) |
| 2555 | return QualType(); |
| 2556 | } |
| 2557 | |
| 2558 | ParamTypes.push_back(NewType); |
| 2559 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2562 | QualType Result = TL.getType(); |
| 2563 | if (getDerived().AlwaysRebuild() || |
| 2564 | ResultType != T->getResultType() || |
| 2565 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2566 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2567 | ParamTypes.data(), |
| 2568 | ParamTypes.size(), |
| 2569 | T->isVariadic(), |
| 2570 | T->getTypeQuals()); |
| 2571 | if (Result.isNull()) |
| 2572 | return QualType(); |
| 2573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2575 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2576 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2577 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2578 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2579 | NewTL.setArg(i, ParamDecls[i]); |
| 2580 | |
| 2581 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2582 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2583 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2584 | template<typename Derived> |
| 2585 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2586 | TypeLocBuilder &TLB, |
| 2587 | FunctionNoProtoTypeLoc TL) { |
| 2588 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2589 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2590 | if (ResultType.isNull()) |
| 2591 | return QualType(); |
| 2592 | |
| 2593 | QualType Result = TL.getType(); |
| 2594 | if (getDerived().AlwaysRebuild() || |
| 2595 | ResultType != T->getResultType()) |
| 2596 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2597 | |
| 2598 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2599 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2600 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2601 | |
| 2602 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2605 | template<typename Derived> QualType |
| 2606 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2607 | UnresolvedUsingTypeLoc TL) { |
| 2608 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2609 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2610 | if (!D) |
| 2611 | return QualType(); |
| 2612 | |
| 2613 | QualType Result = TL.getType(); |
| 2614 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2615 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2616 | if (Result.isNull()) |
| 2617 | return QualType(); |
| 2618 | } |
| 2619 | |
| 2620 | // We might get an arbitrary type spec type back. We should at |
| 2621 | // least always get a type spec type, though. |
| 2622 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2623 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2624 | |
| 2625 | return Result; |
| 2626 | } |
| 2627 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2628 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2629 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2630 | TypedefTypeLoc TL) { |
| 2631 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2632 | TypedefDecl *Typedef |
| 2633 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2634 | if (!Typedef) |
| 2635 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2636 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2637 | QualType Result = TL.getType(); |
| 2638 | if (getDerived().AlwaysRebuild() || |
| 2639 | Typedef != T->getDecl()) { |
| 2640 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2641 | if (Result.isNull()) |
| 2642 | return QualType(); |
| 2643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2644 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2645 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2646 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2647 | |
| 2648 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2649 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2650 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2651 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2652 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2653 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2654 | // typeof expressions are not potentially evaluated contexts |
| 2655 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2657 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2658 | if (E.isInvalid()) |
| 2659 | return QualType(); |
| 2660 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2661 | QualType Result = TL.getType(); |
| 2662 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2663 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2664 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2665 | if (Result.isNull()) |
| 2666 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2667 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2669 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2670 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2671 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2672 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2673 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2674 | |
| 2675 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2677 | |
| 2678 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2679 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2680 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2681 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2682 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2683 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2684 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2685 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2686 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2687 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2688 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2689 | if (Result.isNull()) |
| 2690 | return QualType(); |
| 2691 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2692 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2693 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2694 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2695 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2696 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2697 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2698 | |
| 2699 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2700 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2701 | |
| 2702 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2703 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2704 | DecltypeTypeLoc TL) { |
| 2705 | DecltypeType *T = TL.getTypePtr(); |
| 2706 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2707 | // decltype expressions are not potentially evaluated contexts |
| 2708 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2709 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2710 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2711 | if (E.isInvalid()) |
| 2712 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2714 | QualType Result = TL.getType(); |
| 2715 | if (getDerived().AlwaysRebuild() || |
| 2716 | E.get() != T->getUnderlyingExpr()) { |
| 2717 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2718 | if (Result.isNull()) |
| 2719 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2720 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2721 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2722 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2723 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2724 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2725 | |
| 2726 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2730 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2731 | RecordTypeLoc TL) { |
| 2732 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2733 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2734 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2735 | if (!Record) |
| 2736 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2737 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2738 | QualType Result = TL.getType(); |
| 2739 | if (getDerived().AlwaysRebuild() || |
| 2740 | Record != T->getDecl()) { |
| 2741 | Result = getDerived().RebuildRecordType(Record); |
| 2742 | if (Result.isNull()) |
| 2743 | return QualType(); |
| 2744 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2745 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2746 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2747 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2748 | |
| 2749 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2750 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2751 | |
| 2752 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2753 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2754 | EnumTypeLoc TL) { |
| 2755 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2756 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2757 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2758 | if (!Enum) |
| 2759 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2760 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | QualType Result = TL.getType(); |
| 2762 | if (getDerived().AlwaysRebuild() || |
| 2763 | Enum != T->getDecl()) { |
| 2764 | Result = getDerived().RebuildEnumType(Enum); |
| 2765 | if (Result.isNull()) |
| 2766 | return QualType(); |
| 2767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2768 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2769 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2770 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2771 | |
| 2772 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2773 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2774 | |
| 2775 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2777 | ElaboratedTypeLoc TL) { |
| 2778 | ElaboratedType *T = TL.getTypePtr(); |
| 2779 | |
| 2780 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2781 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2782 | if (Underlying.isNull()) |
| 2783 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2784 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2785 | QualType Result = TL.getType(); |
| 2786 | if (getDerived().AlwaysRebuild() || |
| 2787 | Underlying != T->getUnderlyingType()) { |
| 2788 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2789 | if (Result.isNull()) |
| 2790 | return QualType(); |
| 2791 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2793 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2794 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2795 | |
| 2796 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2797 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2798 | |
| 2799 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2800 | template<typename Derived> |
| 2801 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | TypeLocBuilder &TLB, |
| 2803 | TemplateTypeParmTypeLoc TL) { |
| 2804 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2807 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2808 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2809 | TypeLocBuilder &TLB, |
| 2810 | SubstTemplateTypeParmTypeLoc TL) { |
| 2811 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2815 | inline QualType |
| 2816 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2817 | TypeLocBuilder &TLB, |
| 2818 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2819 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2820 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2821 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2822 | template<typename Derived> |
| 2823 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2824 | const TemplateSpecializationType *TST, |
| 2825 | QualType ObjectType) { |
| 2826 | // FIXME: this entire method is a temporary workaround; callers |
| 2827 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2828 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2829 | // Fake up a TemplateSpecializationTypeLoc. |
| 2830 | TypeLocBuilder TLB; |
| 2831 | TemplateSpecializationTypeLoc TL |
| 2832 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2833 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2834 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2835 | |
| 2836 | TL.setTemplateNameLoc(BaseLoc); |
| 2837 | TL.setLAngleLoc(BaseLoc); |
| 2838 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2839 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2840 | const TemplateArgument &TA = TST->getArg(i); |
| 2841 | TemplateArgumentLoc TAL; |
| 2842 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2843 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2844 | } |
| 2845 | |
| 2846 | TypeLocBuilder IgnoredTLB; |
| 2847 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2851 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2852 | TypeLocBuilder &TLB, |
| 2853 | TemplateSpecializationTypeLoc TL, |
| 2854 | QualType ObjectType) { |
| 2855 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2856 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2857 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2858 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2859 | if (Template.isNull()) |
| 2860 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2861 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2862 | TemplateArgumentListInfo NewTemplateArgs; |
| 2863 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2864 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2865 | |
| 2866 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2867 | TemplateArgumentLoc Loc; |
| 2868 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2869 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2870 | NewTemplateArgs.addArgument(Loc); |
| 2871 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2872 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2873 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2874 | |
| 2875 | QualType Result = |
| 2876 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2877 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2878 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2879 | |
| 2880 | if (!Result.isNull()) { |
| 2881 | TemplateSpecializationTypeLoc NewTL |
| 2882 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2883 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2884 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2885 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2886 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2887 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2888 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2889 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2890 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2892 | |
| 2893 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2894 | QualType |
| 2895 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2896 | QualifiedNameTypeLoc TL) { |
| 2897 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2898 | NestedNameSpecifier *NNS |
| 2899 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2900 | SourceRange()); |
| 2901 | if (!NNS) |
| 2902 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2903 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2904 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2905 | if (Named.isNull()) |
| 2906 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2908 | QualType Result = TL.getType(); |
| 2909 | if (getDerived().AlwaysRebuild() || |
| 2910 | NNS != T->getQualifier() || |
| 2911 | Named != T->getNamedType()) { |
| 2912 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2913 | if (Result.isNull()) |
| 2914 | return QualType(); |
| 2915 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2916 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2917 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2918 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2919 | |
| 2920 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2921 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | |
| 2923 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2924 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2925 | TypenameTypeLoc TL) { |
| 2926 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2927 | |
| 2928 | /* FIXME: preserve source information better than this */ |
| 2929 | SourceRange SR(TL.getNameLoc()); |
| 2930 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2931 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2932 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2933 | if (!NNS) |
| 2934 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2935 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2936 | QualType Result; |
| 2937 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2938 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2939 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2940 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2941 | if (NewTemplateId.isNull()) |
| 2942 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2944 | if (!getDerived().AlwaysRebuild() && |
| 2945 | NNS == T->getQualifier() && |
| 2946 | NewTemplateId == QualType(TemplateId, 0)) |
| 2947 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2948 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2949 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2950 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2951 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2952 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2953 | if (Result.isNull()) |
| 2954 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2955 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2956 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2957 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2958 | |
| 2959 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2962 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2963 | QualType |
| 2964 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2965 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2966 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2967 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2968 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
| 2970 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2971 | QualType |
| 2972 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2973 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2974 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2975 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2976 | } |
| 2977 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2978 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2979 | // Statement transformation |
| 2980 | //===----------------------------------------------------------------------===// |
| 2981 | template<typename Derived> |
| 2982 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2983 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2984 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | template<typename Derived> |
| 2988 | Sema::OwningStmtResult |
| 2989 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2990 | return getDerived().TransformCompoundStmt(S, false); |
| 2991 | } |
| 2992 | |
| 2993 | template<typename Derived> |
| 2994 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2996 | bool IsStmtExpr) { |
| 2997 | bool SubStmtChanged = false; |
| 2998 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2999 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3000 | B != BEnd; ++B) { |
| 3001 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3002 | if (Result.isInvalid()) |
| 3003 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3005 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3006 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3007 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3008 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3009 | if (!getDerived().AlwaysRebuild() && |
| 3010 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3012 | |
| 3013 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3014 | move_arg(Statements), |
| 3015 | S->getRBracLoc(), |
| 3016 | IsStmtExpr); |
| 3017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3019 | template<typename Derived> |
| 3020 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3021 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3022 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3023 | { |
| 3024 | // The case value expressions are not potentially evaluated. |
| 3025 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3027 | // Transform the left-hand case value. |
| 3028 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3029 | if (LHS.isInvalid()) |
| 3030 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3032 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3033 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3034 | if (RHS.isInvalid()) |
| 3035 | return SemaRef.StmtError(); |
| 3036 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3038 | // Build the case statement. |
| 3039 | // Case statements are always rebuilt so that they will attached to their |
| 3040 | // transformed switch statement. |
| 3041 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3042 | move(LHS), |
| 3043 | S->getEllipsisLoc(), |
| 3044 | move(RHS), |
| 3045 | S->getColonLoc()); |
| 3046 | if (Case.isInvalid()) |
| 3047 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3049 | // Transform the statement following the case |
| 3050 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3051 | if (SubStmt.isInvalid()) |
| 3052 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3054 | // Attach the body to the case statement |
| 3055 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3056 | } |
| 3057 | |
| 3058 | template<typename Derived> |
| 3059 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3060 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3061 | // Transform the statement following the default case |
| 3062 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3063 | if (SubStmt.isInvalid()) |
| 3064 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3065 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3066 | // Default statements are always rebuilt |
| 3067 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3068 | move(SubStmt)); |
| 3069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3070 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3071 | template<typename Derived> |
| 3072 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3073 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3074 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3075 | if (SubStmt.isInvalid()) |
| 3076 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3078 | // FIXME: Pass the real colon location in. |
| 3079 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3080 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3081 | move(SubStmt)); |
| 3082 | } |
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 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3085 | Sema::OwningStmtResult |
| 3086 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3087 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3088 | OwningExprResult Cond(SemaRef); |
| 3089 | VarDecl *ConditionVar = 0; |
| 3090 | if (S->getConditionVariable()) { |
| 3091 | ConditionVar |
| 3092 | = cast_or_null<VarDecl>( |
| 3093 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3094 | if (!ConditionVar) |
| 3095 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3096 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3097 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3098 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3099 | if (Cond.isInvalid()) |
| 3100 | return SemaRef.StmtError(); |
| 3101 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3102 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3103 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3104 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3105 | // Transform the "then" branch. |
| 3106 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3107 | if (Then.isInvalid()) |
| 3108 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3110 | // Transform the "else" branch. |
| 3111 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3112 | if (Else.isInvalid()) |
| 3113 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3115 | if (!getDerived().AlwaysRebuild() && |
| 3116 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3117 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3118 | Then.get() == S->getThen() && |
| 3119 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3120 | return SemaRef.Owned(S->Retain()); |
| 3121 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3122 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3123 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | template<typename Derived> |
| 3128 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3129 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3130 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3131 | OwningExprResult Cond(SemaRef); |
| 3132 | VarDecl *ConditionVar = 0; |
| 3133 | if (S->getConditionVariable()) { |
| 3134 | ConditionVar |
| 3135 | = cast_or_null<VarDecl>( |
| 3136 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3137 | if (!ConditionVar) |
| 3138 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3139 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3140 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3141 | |
| 3142 | if (Cond.isInvalid()) |
| 3143 | return SemaRef.StmtError(); |
| 3144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3145 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3146 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3147 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3148 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3149 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3150 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3151 | if (Switch.isInvalid()) |
| 3152 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3153 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3154 | // Transform the body of the switch statement. |
| 3155 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3156 | if (Body.isInvalid()) |
| 3157 | return SemaRef.StmtError(); |
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 | // Complete the switch statement. |
| 3160 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3161 | move(Body)); |
| 3162 | } |
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 | template<typename Derived> |
| 3165 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3168 | OwningExprResult Cond(SemaRef); |
| 3169 | VarDecl *ConditionVar = 0; |
| 3170 | if (S->getConditionVariable()) { |
| 3171 | ConditionVar |
| 3172 | = cast_or_null<VarDecl>( |
| 3173 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3174 | if (!ConditionVar) |
| 3175 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3176 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3177 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3178 | |
| 3179 | if (Cond.isInvalid()) |
| 3180 | return SemaRef.StmtError(); |
| 3181 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3182 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3183 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3184 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3185 | // Transform the body |
| 3186 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3187 | if (Body.isInvalid()) |
| 3188 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3190 | if (!getDerived().AlwaysRebuild() && |
| 3191 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3192 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3193 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | return SemaRef.Owned(S->Retain()); |
| 3195 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3196 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3197 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3198 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3199 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3200 | template<typename Derived> |
| 3201 | Sema::OwningStmtResult |
| 3202 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3203 | // Transform the condition |
| 3204 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3205 | if (Cond.isInvalid()) |
| 3206 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3207 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3208 | // Transform the body |
| 3209 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3210 | if (Body.isInvalid()) |
| 3211 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3212 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3213 | if (!getDerived().AlwaysRebuild() && |
| 3214 | Cond.get() == S->getCond() && |
| 3215 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3216 | return SemaRef.Owned(S->Retain()); |
| 3217 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3218 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3219 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3220 | S->getRParenLoc()); |
| 3221 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3222 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3223 | template<typename Derived> |
| 3224 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | // Transform the initialization statement |
| 3227 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3228 | if (Init.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 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3232 | OwningExprResult Cond(SemaRef); |
| 3233 | VarDecl *ConditionVar = 0; |
| 3234 | if (S->getConditionVariable()) { |
| 3235 | ConditionVar |
| 3236 | = cast_or_null<VarDecl>( |
| 3237 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3238 | if (!ConditionVar) |
| 3239 | return SemaRef.StmtError(); |
| 3240 | } else { |
| 3241 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3242 | |
| 3243 | if (Cond.isInvalid()) |
| 3244 | return SemaRef.StmtError(); |
| 3245 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3247 | // Transform the increment |
| 3248 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3249 | if (Inc.isInvalid()) |
| 3250 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3251 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3252 | // Transform the body |
| 3253 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3254 | if (Body.isInvalid()) |
| 3255 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3256 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3257 | if (!getDerived().AlwaysRebuild() && |
| 3258 | Init.get() == S->getInit() && |
| 3259 | Cond.get() == S->getCond() && |
| 3260 | Inc.get() == S->getInc() && |
| 3261 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | return SemaRef.Owned(S->Retain()); |
| 3263 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3264 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3265 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3266 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3267 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3268 | S->getRParenLoc(), move(Body)); |
| 3269 | } |
| 3270 | |
| 3271 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3272 | Sema::OwningStmtResult |
| 3273 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3274 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | S->getLabel()); |
| 3277 | } |
| 3278 | |
| 3279 | template<typename Derived> |
| 3280 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3283 | if (Target.isInvalid()) |
| 3284 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3286 | if (!getDerived().AlwaysRebuild() && |
| 3287 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3288 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3289 | |
| 3290 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3291 | move(Target)); |
| 3292 | } |
| 3293 | |
| 3294 | template<typename Derived> |
| 3295 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3296 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3297 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3300 | template<typename Derived> |
| 3301 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3302 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3303 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | } |
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 | template<typename Derived> |
| 3307 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3310 | if (Result.isInvalid()) |
| 3311 | return SemaRef.StmtError(); |
| 3312 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | // to tell whether the return type of the function has changed. |
| 3315 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3316 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3318 | template<typename Derived> |
| 3319 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3321 | bool DeclChanged = false; |
| 3322 | llvm::SmallVector<Decl *, 4> Decls; |
| 3323 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3324 | D != DEnd; ++D) { |
| 3325 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3326 | if (!Transformed) |
| 3327 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3329 | if (Transformed != *D) |
| 3330 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3331 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3332 | Decls.push_back(Transformed); |
| 3333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | return SemaRef.Owned(S->Retain()); |
| 3337 | |
| 3338 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | S->getStartLoc(), S->getEndLoc()); |
| 3340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | template<typename Derived> |
| 3343 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3345 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | template<typename Derived> |
| 3350 | Sema::OwningStmtResult |
| 3351 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3352 | |
| 3353 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3354 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
| 3355 | OwningExprResult AsmString(SemaRef); |
| 3356 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3357 | |
| 3358 | bool ExprsChanged = false; |
| 3359 | |
| 3360 | // Go through the outputs. |
| 3361 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
| 3362 | // No need to transform the constraint literal. |
| 3363 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3364 | |
| 3365 | // Transform the output expr. |
| 3366 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3367 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3368 | if (Result.isInvalid()) |
| 3369 | return SemaRef.StmtError(); |
| 3370 | |
| 3371 | ExprsChanged |= Result.get() != OutputExpr; |
| 3372 | |
| 3373 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3374 | } |
| 3375 | |
| 3376 | // Go through the inputs. |
| 3377 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
| 3378 | // No need to transform the constraint literal. |
| 3379 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3380 | |
| 3381 | // Transform the input expr. |
| 3382 | Expr *InputExpr = S->getInputExpr(I); |
| 3383 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3384 | if (Result.isInvalid()) |
| 3385 | return SemaRef.StmtError(); |
| 3386 | |
| 3387 | ExprsChanged |= Result.get() != InputExpr; |
| 3388 | |
| 3389 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3390 | } |
| 3391 | |
| 3392 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3393 | return SemaRef.Owned(S->Retain()); |
| 3394 | |
| 3395 | // Go through the clobbers. |
| 3396 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3397 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3398 | |
| 3399 | // No need to transform the asm string literal. |
| 3400 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3401 | |
| 3402 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3403 | S->isSimple(), |
| 3404 | S->isVolatile(), |
| 3405 | S->getNumOutputs(), |
| 3406 | S->getNumInputs(), |
| 3407 | S->begin_output_names(), |
| 3408 | move_arg(Constraints), |
| 3409 | move_arg(Exprs), |
| 3410 | move(AsmString), |
| 3411 | move_arg(Clobbers), |
| 3412 | S->getRParenLoc(), |
| 3413 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | |
| 3417 | template<typename Derived> |
| 3418 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3419 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3420 | // FIXME: Implement this |
| 3421 | assert(false && "Cannot transform an Objective-C @try statement"); |
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 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3424 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3425 | template<typename Derived> |
| 3426 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3428 | // FIXME: Implement this |
| 3429 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3430 | return SemaRef.Owned(S->Retain()); |
| 3431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | template<typename Derived> |
| 3434 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3436 | // FIXME: Implement this |
| 3437 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3440 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3441 | template<typename Derived> |
| 3442 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3443 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3444 | // FIXME: Implement this |
| 3445 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3449 | template<typename Derived> |
| 3450 | Sema::OwningStmtResult |
| 3451 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3453 | // FIXME: Implement this |
| 3454 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3455 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | template<typename Derived> |
| 3459 | Sema::OwningStmtResult |
| 3460 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | // FIXME: Implement this |
| 3463 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | |
| 3468 | template<typename Derived> |
| 3469 | Sema::OwningStmtResult |
| 3470 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3471 | // Transform the exception declaration, if any. |
| 3472 | VarDecl *Var = 0; |
| 3473 | if (S->getExceptionDecl()) { |
| 3474 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3475 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3476 | ExceptionDecl->getDeclName()); |
| 3477 | |
| 3478 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3479 | if (T.isNull()) |
| 3480 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3481 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3482 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3483 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3484 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3485 | ExceptionDecl->getIdentifier(), |
| 3486 | ExceptionDecl->getLocation(), |
| 3487 | /*FIXME: Inaccurate*/ |
| 3488 | SourceRange(ExceptionDecl->getLocation())); |
| 3489 | if (!Var || Var->isInvalidDecl()) { |
| 3490 | if (Var) |
| 3491 | Var->Destroy(SemaRef.Context); |
| 3492 | return SemaRef.StmtError(); |
| 3493 | } |
| 3494 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3495 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3496 | // Transform the actual exception handler. |
| 3497 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3498 | if (Handler.isInvalid()) { |
| 3499 | if (Var) |
| 3500 | Var->Destroy(SemaRef.Context); |
| 3501 | return SemaRef.StmtError(); |
| 3502 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3504 | if (!getDerived().AlwaysRebuild() && |
| 3505 | !Var && |
| 3506 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3507 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3508 | |
| 3509 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3510 | Var, |
| 3511 | move(Handler)); |
| 3512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3513 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3514 | template<typename Derived> |
| 3515 | Sema::OwningStmtResult |
| 3516 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3517 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3519 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3520 | if (TryBlock.isInvalid()) |
| 3521 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3522 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3523 | // Transform the handlers. |
| 3524 | bool HandlerChanged = false; |
| 3525 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3526 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3528 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3529 | if (Handler.isInvalid()) |
| 3530 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3532 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3533 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | if (!getDerived().AlwaysRebuild() && |
| 3537 | TryBlock.get() == S->getTryBlock() && |
| 3538 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3540 | |
| 3541 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3542 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3546 | // Expression transformation |
| 3547 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | template<typename Derived> |
| 3549 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3550 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3551 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | |
| 3554 | template<typename Derived> |
| 3555 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3556 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3557 | NestedNameSpecifier *Qualifier = 0; |
| 3558 | if (E->getQualifier()) { |
| 3559 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3560 | E->getQualifierRange()); |
| 3561 | if (!Qualifier) |
| 3562 | return SemaRef.ExprError(); |
| 3563 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3564 | |
| 3565 | ValueDecl *ND |
| 3566 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3567 | if (!ND) |
| 3568 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3570 | if (!getDerived().AlwaysRebuild() && |
| 3571 | Qualifier == E->getQualifier() && |
| 3572 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3573 | !E->hasExplicitTemplateArgumentList()) { |
| 3574 | |
| 3575 | // Mark it referenced in the new context regardless. |
| 3576 | // FIXME: this is a bit instantiation-specific. |
| 3577 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3578 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3580 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3581 | |
| 3582 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3583 | if (E->hasExplicitTemplateArgumentList()) { |
| 3584 | TemplateArgs = &TransArgs; |
| 3585 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3586 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3587 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3588 | TemplateArgumentLoc Loc; |
| 3589 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3590 | return SemaRef.ExprError(); |
| 3591 | TransArgs.addArgument(Loc); |
| 3592 | } |
| 3593 | } |
| 3594 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3595 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3596 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3598 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3599 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3600 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3601 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3602 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3605 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3606 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3607 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3608 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3615 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3617 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3619 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3621 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3623 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3624 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3625 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3626 | return SemaRef.Owned(E->Retain()); |
| 3627 | } |
| 3628 | |
| 3629 | template<typename Derived> |
| 3630 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3631 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3633 | if (SubExpr.isInvalid()) |
| 3634 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3636 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | return SemaRef.Owned(E->Retain()); |
| 3638 | |
| 3639 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3640 | E->getRParen()); |
| 3641 | } |
| 3642 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | template<typename Derived> |
| 3644 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3645 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3646 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3647 | if (SubExpr.isInvalid()) |
| 3648 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3650 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | return SemaRef.Owned(E->Retain()); |
| 3652 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3653 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3654 | E->getOpcode(), |
| 3655 | move(SubExpr)); |
| 3656 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3658 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3660 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3661 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3662 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3663 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3664 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3665 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3666 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3668 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3669 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3671 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3673 | E->getSourceRange()); |
| 3674 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3675 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3676 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3678 | // C++0x [expr.sizeof]p1: |
| 3679 | // The operand is either an expression, which is an unevaluated operand |
| 3680 | // [...] |
| 3681 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3683 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3684 | if (SubExpr.isInvalid()) |
| 3685 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3687 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3688 | return SemaRef.Owned(E->Retain()); |
| 3689 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3691 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3692 | E->isSizeOf(), |
| 3693 | E->getSourceRange()); |
| 3694 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3695 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3696 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3697 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3698 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3699 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3700 | if (LHS.isInvalid()) |
| 3701 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3703 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3704 | if (RHS.isInvalid()) |
| 3705 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3706 | |
| 3707 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3708 | if (!getDerived().AlwaysRebuild() && |
| 3709 | LHS.get() == E->getLHS() && |
| 3710 | RHS.get() == E->getRHS()) |
| 3711 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3713 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3714 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3715 | move(RHS), |
| 3716 | E->getRBracketLoc()); |
| 3717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | |
| 3719 | template<typename Derived> |
| 3720 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3721 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | // Transform the callee. |
| 3723 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3724 | if (Callee.isInvalid()) |
| 3725 | return SemaRef.ExprError(); |
| 3726 | |
| 3727 | // Transform arguments. |
| 3728 | bool ArgChanged = false; |
| 3729 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3730 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3731 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3732 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3733 | if (Arg.isInvalid()) |
| 3734 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3735 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3736 | // FIXME: Wrong source location information for the ','. |
| 3737 | FakeCommaLocs.push_back( |
| 3738 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3739 | |
| 3740 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3741 | Args.push_back(Arg.takeAs<Expr>()); |
| 3742 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3743 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3744 | if (!getDerived().AlwaysRebuild() && |
| 3745 | Callee.get() == E->getCallee() && |
| 3746 | !ArgChanged) |
| 3747 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3749 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3750 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3752 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3753 | move_arg(Args), |
| 3754 | FakeCommaLocs.data(), |
| 3755 | E->getRParenLoc()); |
| 3756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3757 | |
| 3758 | template<typename Derived> |
| 3759 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3760 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3761 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3762 | if (Base.isInvalid()) |
| 3763 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3765 | NestedNameSpecifier *Qualifier = 0; |
| 3766 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3767 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3768 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3769 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3770 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3771 | return SemaRef.ExprError(); |
| 3772 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3774 | ValueDecl *Member |
| 3775 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | if (!Member) |
| 3777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3779 | if (!getDerived().AlwaysRebuild() && |
| 3780 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3781 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3782 | Member == E->getMemberDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3783 | !E->hasExplicitTemplateArgumentList()) { |
| 3784 | |
| 3785 | // Mark it referenced in the new context regardless. |
| 3786 | // FIXME: this is a bit instantiation-specific. |
| 3787 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3789 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3790 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3791 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3792 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3793 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3794 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3795 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3796 | TemplateArgumentLoc Loc; |
| 3797 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3798 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3799 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3800 | } |
| 3801 | } |
| 3802 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3803 | // FIXME: Bogus source location for the operator |
| 3804 | SourceLocation FakeOperatorLoc |
| 3805 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3806 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3807 | // FIXME: to do this check properly, we will need to preserve the |
| 3808 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3809 | // base (and therefore couldn't do the check) and a |
| 3810 | // nested-name-qualifier (and therefore could do the lookup). |
| 3811 | NamedDecl *FirstQualifierInScope = 0; |
| 3812 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3813 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3814 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3815 | Qualifier, |
| 3816 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3817 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3818 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3819 | (E->hasExplicitTemplateArgumentList() |
| 3820 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3821 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3822 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3823 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3824 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3825 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3826 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3827 | assert(false && "Cannot transform abstract class"); |
| 3828 | return SemaRef.Owned(E->Retain()); |
| 3829 | } |
| 3830 | |
| 3831 | template<typename Derived> |
| 3832 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3833 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3835 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3839 | if (RHS.isInvalid()) |
| 3840 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | if (!getDerived().AlwaysRebuild() && |
| 3843 | LHS.get() == E->getLHS() && |
| 3844 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3845 | return SemaRef.Owned(E->Retain()); |
| 3846 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3847 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3848 | move(LHS), move(RHS)); |
| 3849 | } |
| 3850 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3851 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3852 | Sema::OwningExprResult |
| 3853 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3854 | CompoundAssignOperator *E) { |
| 3855 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3859 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3860 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3861 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3862 | if (Cond.isInvalid()) |
| 3863 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3864 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3865 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3866 | if (LHS.isInvalid()) |
| 3867 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3868 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3869 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3870 | if (RHS.isInvalid()) |
| 3871 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3872 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3873 | if (!getDerived().AlwaysRebuild() && |
| 3874 | Cond.get() == E->getCond() && |
| 3875 | LHS.get() == E->getLHS() && |
| 3876 | RHS.get() == E->getRHS()) |
| 3877 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3878 | |
| 3879 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3880 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3882 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3883 | move(RHS)); |
| 3884 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3885 | |
| 3886 | template<typename Derived> |
| 3887 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3888 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3889 | // Implicit casts are eliminated during transformation, since they |
| 3890 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3891 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3894 | template<typename Derived> |
| 3895 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3896 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | assert(false && "Cannot transform abstract class"); |
| 3898 | return SemaRef.Owned(E->Retain()); |
| 3899 | } |
| 3900 | |
| 3901 | template<typename Derived> |
| 3902 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3903 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3904 | TypeSourceInfo *OldT; |
| 3905 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | { |
| 3907 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3908 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3909 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3910 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3912 | OldT = E->getTypeInfoAsWritten(); |
| 3913 | NewT = getDerived().TransformType(OldT); |
| 3914 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | return SemaRef.ExprError(); |
| 3916 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3918 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3919 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | if (SubExpr.isInvalid()) |
| 3921 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3923 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3924 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | return SemaRef.Owned(E->Retain()); |
| 3927 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3928 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3929 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | E->getRParenLoc(), |
| 3931 | move(SubExpr)); |
| 3932 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3936 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3937 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3938 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3939 | if (!NewT) |
| 3940 | return SemaRef.ExprError(); |
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 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3943 | if (Init.isInvalid()) |
| 3944 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3946 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3947 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3951 | // Note: the expression type doesn't necessarily match the |
| 3952 | // type-as-written, but that's okay, because it should always be |
| 3953 | // derivable from the initializer. |
| 3954 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3955 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3957 | move(Init)); |
| 3958 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3959 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3960 | template<typename Derived> |
| 3961 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3962 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3964 | if (Base.isInvalid()) |
| 3965 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3967 | if (!getDerived().AlwaysRebuild() && |
| 3968 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3969 | return SemaRef.Owned(E->Retain()); |
| 3970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3971 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3974 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3975 | E->getAccessorLoc(), |
| 3976 | E->getAccessor()); |
| 3977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3979 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3981 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3982 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3984 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3985 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3986 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3987 | if (Init.isInvalid()) |
| 3988 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3989 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3990 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3991 | Inits.push_back(Init.takeAs<Expr>()); |
| 3992 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3994 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3995 | return SemaRef.Owned(E->Retain()); |
| 3996 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3997 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3998 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
| 4002 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4003 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4004 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4006 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4007 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4008 | if (Init.isInvalid()) |
| 4009 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4010 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4011 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4013 | bool ExprChanged = false; |
| 4014 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4015 | DEnd = E->designators_end(); |
| 4016 | D != DEnd; ++D) { |
| 4017 | if (D->isFieldDesignator()) { |
| 4018 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4019 | D->getDotLoc(), |
| 4020 | D->getFieldLoc())); |
| 4021 | continue; |
| 4022 | } |
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 (D->isArrayDesignator()) { |
| 4025 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4026 | if (Index.isInvalid()) |
| 4027 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
| 4029 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4030 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4032 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4033 | ArrayExprs.push_back(Index.release()); |
| 4034 | continue; |
| 4035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4037 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4038 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4039 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4040 | if (Start.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 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4044 | if (End.isInvalid()) |
| 4045 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
| 4047 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | End.get(), |
| 4049 | D->getLBracketLoc(), |
| 4050 | D->getEllipsisLoc())); |
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 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4053 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4055 | ArrayExprs.push_back(Start.release()); |
| 4056 | ArrayExprs.push_back(End.release()); |
| 4057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4059 | if (!getDerived().AlwaysRebuild() && |
| 4060 | Init.get() == E->getInit() && |
| 4061 | !ExprChanged) |
| 4062 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4065 | E->getEqualOrColonLoc(), |
| 4066 | E->usesGNUSyntax(), move(Init)); |
| 4067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4070 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4071 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4072 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4073 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4074 | |
| 4075 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4076 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | QualType T = getDerived().TransformType(E->getType()); |
| 4078 | if (T.isNull()) |
| 4079 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4082 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | return SemaRef.Owned(E->Retain()); |
| 4084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4085 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4090 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | // FIXME: Do we want the type as written? |
| 4092 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4094 | { |
| 4095 | // FIXME: Source location isn't quite accurate. |
| 4096 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4097 | T = getDerived().TransformType(E->getType()); |
| 4098 | if (T.isNull()) |
| 4099 | return SemaRef.ExprError(); |
| 4100 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4101 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4102 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4103 | if (SubExpr.isInvalid()) |
| 4104 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4106 | if (!getDerived().AlwaysRebuild() && |
| 4107 | T == E->getType() && |
| 4108 | SubExpr.get() == E->getSubExpr()) |
| 4109 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4111 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4112 | T, E->getRParenLoc()); |
| 4113 | } |
| 4114 | |
| 4115 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4117 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | bool ArgumentChanged = false; |
| 4119 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4120 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4121 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4122 | if (Init.isInvalid()) |
| 4123 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4124 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4125 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4126 | Inits.push_back(Init.takeAs<Expr>()); |
| 4127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4128 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4129 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4130 | move_arg(Inits), |
| 4131 | E->getRParenLoc()); |
| 4132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4134 | /// \brief Transform an address-of-label expression. |
| 4135 | /// |
| 4136 | /// By default, the transformation of an address-of-label expression always |
| 4137 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4138 | /// the corresponding label statement by semantic analysis. |
| 4139 | template<typename Derived> |
| 4140 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4141 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4142 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4143 | E->getLabel()); |
| 4144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
| 4146 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4147 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4148 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4151 | if (SubStmt.isInvalid()) |
| 4152 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | if (!getDerived().AlwaysRebuild() && |
| 4155 | SubStmt.get() == E->getSubStmt()) |
| 4156 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | |
| 4158 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | move(SubStmt), |
| 4160 | E->getRParenLoc()); |
| 4161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4163 | template<typename Derived> |
| 4164 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4165 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4166 | QualType T1, T2; |
| 4167 | { |
| 4168 | // FIXME: Source location isn't quite accurate. |
| 4169 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4172 | if (T1.isNull()) |
| 4173 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4175 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4176 | if (T2.isNull()) |
| 4177 | return SemaRef.ExprError(); |
| 4178 | } |
| 4179 | |
| 4180 | if (!getDerived().AlwaysRebuild() && |
| 4181 | T1 == E->getArgType1() && |
| 4182 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | return SemaRef.Owned(E->Retain()); |
| 4184 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4186 | T1, T2, E->getRParenLoc()); |
| 4187 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4189 | template<typename Derived> |
| 4190 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4191 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4193 | if (Cond.isInvalid()) |
| 4194 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4197 | if (LHS.isInvalid()) |
| 4198 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4201 | if (RHS.isInvalid()) |
| 4202 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4204 | if (!getDerived().AlwaysRebuild() && |
| 4205 | Cond.get() == E->getCond() && |
| 4206 | LHS.get() == E->getLHS() && |
| 4207 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | return SemaRef.Owned(E->Retain()); |
| 4209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4211 | move(Cond), move(LHS), move(RHS), |
| 4212 | E->getRParenLoc()); |
| 4213 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4217 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | template<typename Derived> |
| 4222 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4223 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4224 | switch (E->getOperator()) { |
| 4225 | case OO_New: |
| 4226 | case OO_Delete: |
| 4227 | case OO_Array_New: |
| 4228 | case OO_Array_Delete: |
| 4229 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4230 | return SemaRef.ExprError(); |
| 4231 | |
| 4232 | case OO_Call: { |
| 4233 | // This is a call to an object's operator(). |
| 4234 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4235 | |
| 4236 | // Transform the object itself. |
| 4237 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4238 | if (Object.isInvalid()) |
| 4239 | return SemaRef.ExprError(); |
| 4240 | |
| 4241 | // FIXME: Poor location information |
| 4242 | SourceLocation FakeLParenLoc |
| 4243 | = SemaRef.PP.getLocForEndOfToken( |
| 4244 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4245 | |
| 4246 | // Transform the call arguments. |
| 4247 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4248 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4249 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4250 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4251 | break; |
| 4252 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4253 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4254 | if (Arg.isInvalid()) |
| 4255 | return SemaRef.ExprError(); |
| 4256 | |
| 4257 | // FIXME: Poor source location information. |
| 4258 | SourceLocation FakeCommaLoc |
| 4259 | = SemaRef.PP.getLocForEndOfToken( |
| 4260 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4261 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4262 | Args.push_back(Arg.release()); |
| 4263 | } |
| 4264 | |
| 4265 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4266 | move_arg(Args), |
| 4267 | FakeCommaLocs.data(), |
| 4268 | E->getLocEnd()); |
| 4269 | } |
| 4270 | |
| 4271 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4272 | case OO_##Name: |
| 4273 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4274 | #include "clang/Basic/OperatorKinds.def" |
| 4275 | case OO_Subscript: |
| 4276 | // Handled below. |
| 4277 | break; |
| 4278 | |
| 4279 | case OO_Conditional: |
| 4280 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4281 | return SemaRef.ExprError(); |
| 4282 | |
| 4283 | case OO_None: |
| 4284 | case NUM_OVERLOADED_OPERATORS: |
| 4285 | llvm_unreachable("not an overloaded operator?"); |
| 4286 | return SemaRef.ExprError(); |
| 4287 | } |
| 4288 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4290 | if (Callee.isInvalid()) |
| 4291 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4292 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4293 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4294 | if (First.isInvalid()) |
| 4295 | return SemaRef.ExprError(); |
| 4296 | |
| 4297 | OwningExprResult Second(SemaRef); |
| 4298 | if (E->getNumArgs() == 2) { |
| 4299 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4300 | if (Second.isInvalid()) |
| 4301 | return SemaRef.ExprError(); |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 4305 | Callee.get() == E->getCallee() && |
| 4306 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4308 | return SemaRef.Owned(E->Retain()); |
| 4309 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4311 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | move(First), |
| 4314 | move(Second)); |
| 4315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4317 | template<typename Derived> |
| 4318 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4319 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4320 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4322 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4323 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4325 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4326 | TypeSourceInfo *OldT; |
| 4327 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | { |
| 4329 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4332 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4333 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4334 | OldT = E->getTypeInfoAsWritten(); |
| 4335 | NewT = getDerived().TransformType(OldT); |
| 4336 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | return SemaRef.ExprError(); |
| 4338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4340 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4341 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4342 | if (SubExpr.isInvalid()) |
| 4343 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4345 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4346 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4347 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | return SemaRef.Owned(E->Retain()); |
| 4349 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4352 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4353 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4354 | SourceLocation FakeRParenLoc |
| 4355 | = SemaRef.PP.getLocForEndOfToken( |
| 4356 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4357 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4360 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4361 | FakeRAngleLoc, |
| 4362 | FakeRAngleLoc, |
| 4363 | move(SubExpr), |
| 4364 | FakeRParenLoc); |
| 4365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | template<typename Derived> |
| 4368 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4369 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4370 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
| 4373 | template<typename Derived> |
| 4374 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4375 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4376 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | template<typename Derived> |
| 4380 | Sema::OwningExprResult |
| 4381 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4382 | CXXReinterpretCastExpr *E) { |
| 4383 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | template<typename Derived> |
| 4387 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4388 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4389 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | template<typename Derived> |
| 4393 | Sema::OwningExprResult |
| 4394 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4395 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4396 | TypeSourceInfo *OldT; |
| 4397 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | { |
| 4399 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4400 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4401 | OldT = E->getTypeInfoAsWritten(); |
| 4402 | NewT = getDerived().TransformType(OldT); |
| 4403 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | return SemaRef.ExprError(); |
| 4405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4406 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4407 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4408 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | if (SubExpr.isInvalid()) |
| 4410 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4413 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | return SemaRef.Owned(E->Retain()); |
| 4416 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | // FIXME: The end of the type's source range is wrong |
| 4418 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4419 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4420 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4422 | move(SubExpr), |
| 4423 | E->getRParenLoc()); |
| 4424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4426 | template<typename Derived> |
| 4427 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4428 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4429 | if (E->isTypeOperand()) { |
| 4430 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4431 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4433 | if (T.isNull()) |
| 4434 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4436 | if (!getDerived().AlwaysRebuild() && |
| 4437 | T == E->getTypeOperand()) |
| 4438 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4441 | /*FIXME:*/E->getLocStart(), |
| 4442 | T, |
| 4443 | E->getLocEnd()); |
| 4444 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | // We don't know whether the expression is potentially evaluated until |
| 4447 | // after we perform semantic analysis, so the expression is potentially |
| 4448 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4449 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4450 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4453 | if (SubExpr.isInvalid()) |
| 4454 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | if (!getDerived().AlwaysRebuild() && |
| 4457 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | return SemaRef.Owned(E->Retain()); |
| 4459 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4461 | /*FIXME:*/E->getLocStart(), |
| 4462 | move(SubExpr), |
| 4463 | E->getLocEnd()); |
| 4464 | } |
| 4465 | |
| 4466 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4468 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | template<typename Derived> |
| 4473 | Sema::OwningExprResult |
| 4474 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4475 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4477 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | template<typename Derived> |
| 4480 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4481 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4484 | QualType T = getDerived().TransformType(E->getType()); |
| 4485 | if (T.isNull()) |
| 4486 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | if (!getDerived().AlwaysRebuild() && |
| 4489 | T == E->getType()) |
| 4490 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4491 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4492 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4495 | template<typename Derived> |
| 4496 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4497 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4499 | if (SubExpr.isInvalid()) |
| 4500 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | if (!getDerived().AlwaysRebuild() && |
| 4503 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4505 | |
| 4506 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4507 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | template<typename Derived> |
| 4510 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4511 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4513 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4514 | if (!Param) |
| 4515 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4516 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4517 | if (getDerived().AlwaysRebuild() && |
| 4518 | Param == E->getParam()) |
| 4519 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4520 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4521 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | template<typename Derived> |
| 4525 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4526 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4527 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4528 | |
| 4529 | QualType T = getDerived().TransformType(E->getType()); |
| 4530 | if (T.isNull()) |
| 4531 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4533 | if (!getDerived().AlwaysRebuild() && |
| 4534 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4535 | return SemaRef.Owned(E->Retain()); |
| 4536 | |
| 4537 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4538 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4539 | T, |
| 4540 | E->getRParenLoc()); |
| 4541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | template<typename Derived> |
| 4544 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4545 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | // Transform the type that we're allocating |
| 4547 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4548 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4549 | if (AllocType.isNull()) |
| 4550 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4552 | // Transform the size of the array we're allocating (if any). |
| 4553 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4554 | if (ArraySize.isInvalid()) |
| 4555 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | // Transform the placement arguments (if any). |
| 4558 | bool ArgumentChanged = false; |
| 4559 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4560 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4561 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4562 | if (Arg.isInvalid()) |
| 4563 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4566 | PlacementArgs.push_back(Arg.take()); |
| 4567 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4568 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4569 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4571 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4572 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4573 | if (Arg.isInvalid()) |
| 4574 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4576 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4577 | ConstructorArgs.push_back(Arg.take()); |
| 4578 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4579 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4580 | if (!getDerived().AlwaysRebuild() && |
| 4581 | AllocType == E->getAllocatedType() && |
| 4582 | ArraySize.get() == E->getArraySize() && |
| 4583 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | return SemaRef.Owned(E->Retain()); |
| 4585 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4586 | if (!ArraySize.get()) { |
| 4587 | // If no array size was specified, but the new expression was |
| 4588 | // instantiated with an array type (e.g., "new T" where T is |
| 4589 | // instantiated with "int[4]"), extract the outer bound from the |
| 4590 | // array type as our array size. We do this with constant and |
| 4591 | // dependently-sized array types. |
| 4592 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4593 | if (!ArrayT) { |
| 4594 | // Do nothing |
| 4595 | } else if (const ConstantArrayType *ConsArrayT |
| 4596 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4597 | ArraySize |
| 4598 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4599 | ConsArrayT->getSize(), |
| 4600 | SemaRef.Context.getSizeType(), |
| 4601 | /*FIXME:*/E->getLocStart())); |
| 4602 | AllocType = ConsArrayT->getElementType(); |
| 4603 | } else if (const DependentSizedArrayType *DepArrayT |
| 4604 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4605 | if (DepArrayT->getSizeExpr()) { |
| 4606 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4607 | AllocType = DepArrayT->getElementType(); |
| 4608 | } |
| 4609 | } |
| 4610 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4612 | E->isGlobalNew(), |
| 4613 | /*FIXME:*/E->getLocStart(), |
| 4614 | move_arg(PlacementArgs), |
| 4615 | /*FIXME:*/E->getLocStart(), |
| 4616 | E->isParenTypeId(), |
| 4617 | AllocType, |
| 4618 | /*FIXME:*/E->getLocStart(), |
| 4619 | /*FIXME:*/SourceRange(), |
| 4620 | move(ArraySize), |
| 4621 | /*FIXME:*/E->getLocStart(), |
| 4622 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4623 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4624 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4625 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4626 | template<typename Derived> |
| 4627 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4628 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4629 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4630 | if (Operand.isInvalid()) |
| 4631 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | Operand.get() == E->getArgument()) |
| 4635 | return SemaRef.Owned(E->Retain()); |
| 4636 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4638 | E->isGlobalDelete(), |
| 4639 | E->isArrayForm(), |
| 4640 | move(Operand)); |
| 4641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4642 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | template<typename Derived> |
| 4644 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4645 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4646 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4647 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4648 | if (Base.isInvalid()) |
| 4649 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4650 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4651 | NestedNameSpecifier *Qualifier |
| 4652 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4653 | E->getQualifierRange()); |
| 4654 | if (E->getQualifier() && !Qualifier) |
| 4655 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4657 | QualType DestroyedType; |
| 4658 | { |
| 4659 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4660 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4661 | if (DestroyedType.isNull()) |
| 4662 | return SemaRef.ExprError(); |
| 4663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4665 | if (!getDerived().AlwaysRebuild() && |
| 4666 | Base.get() == E->getBase() && |
| 4667 | Qualifier == E->getQualifier() && |
| 4668 | DestroyedType == E->getDestroyedType()) |
| 4669 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4671 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4672 | E->getOperatorLoc(), |
| 4673 | E->isArrow(), |
| 4674 | E->getDestroyedTypeLoc(), |
| 4675 | DestroyedType, |
| 4676 | Qualifier, |
| 4677 | E->getQualifierRange()); |
| 4678 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4680 | template<typename Derived> |
| 4681 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4682 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4683 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4684 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4685 | |
| 4686 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4687 | Sema::LookupOrdinaryName); |
| 4688 | |
| 4689 | // Transform all the decls. |
| 4690 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4691 | E = Old->decls_end(); I != E; ++I) { |
| 4692 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4693 | if (!InstD) { |
| 4694 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4695 | // This can happen because of dependent hiding. |
| 4696 | if (isa<UsingShadowDecl>(*I)) |
| 4697 | continue; |
| 4698 | else |
| 4699 | return SemaRef.ExprError(); |
| 4700 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4701 | |
| 4702 | // Expand using declarations. |
| 4703 | if (isa<UsingDecl>(InstD)) { |
| 4704 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4705 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4706 | E = UD->shadow_end(); I != E; ++I) |
| 4707 | R.addDecl(*I); |
| 4708 | continue; |
| 4709 | } |
| 4710 | |
| 4711 | R.addDecl(InstD); |
| 4712 | } |
| 4713 | |
| 4714 | // Resolve a kind, but don't do any further analysis. If it's |
| 4715 | // ambiguous, the callee needs to deal with it. |
| 4716 | R.resolveKind(); |
| 4717 | |
| 4718 | // Rebuild the nested-name qualifier, if present. |
| 4719 | CXXScopeSpec SS; |
| 4720 | NestedNameSpecifier *Qualifier = 0; |
| 4721 | if (Old->getQualifier()) { |
| 4722 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4723 | Old->getQualifierRange()); |
| 4724 | if (!Qualifier) |
| 4725 | return SemaRef.ExprError(); |
| 4726 | |
| 4727 | SS.setScopeRep(Qualifier); |
| 4728 | SS.setRange(Old->getQualifierRange()); |
| 4729 | } |
| 4730 | |
| 4731 | // If we have no template arguments, it's a normal declaration name. |
| 4732 | if (!Old->hasExplicitTemplateArgs()) |
| 4733 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4734 | |
| 4735 | // If we have template arguments, rebuild them, then rebuild the |
| 4736 | // templateid expression. |
| 4737 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4738 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4739 | TemplateArgumentLoc Loc; |
| 4740 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4741 | return SemaRef.ExprError(); |
| 4742 | TransArgs.addArgument(Loc); |
| 4743 | } |
| 4744 | |
| 4745 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4746 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4749 | template<typename Derived> |
| 4750 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4751 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4754 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4755 | if (T.isNull()) |
| 4756 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4757 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4758 | if (!getDerived().AlwaysRebuild() && |
| 4759 | T == E->getQueriedType()) |
| 4760 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4761 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4762 | // FIXME: Bad location information |
| 4763 | SourceLocation FakeLParenLoc |
| 4764 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | |
| 4766 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | E->getLocStart(), |
| 4768 | /*FIXME:*/FakeLParenLoc, |
| 4769 | T, |
| 4770 | E->getLocEnd()); |
| 4771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | template<typename Derived> |
| 4774 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4775 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4776 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4777 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4778 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4779 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | if (!NNS) |
| 4781 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
| 4783 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4784 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4785 | if (!Name) |
| 4786 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4788 | if (!E->hasExplicitTemplateArgs()) { |
| 4789 | if (!getDerived().AlwaysRebuild() && |
| 4790 | NNS == E->getQualifier() && |
| 4791 | Name == E->getDeclName()) |
| 4792 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4793 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4794 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4795 | E->getQualifierRange(), |
| 4796 | Name, E->getLocation(), |
| 4797 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4798 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4799 | |
| 4800 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4802 | TemplateArgumentLoc Loc; |
| 4803 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4804 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4805 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4808 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4809 | E->getQualifierRange(), |
| 4810 | Name, E->getLocation(), |
| 4811 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | template<typename Derived> |
| 4815 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4816 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4818 | |
| 4819 | QualType T = getDerived().TransformType(E->getType()); |
| 4820 | if (T.isNull()) |
| 4821 | return SemaRef.ExprError(); |
| 4822 | |
| 4823 | CXXConstructorDecl *Constructor |
| 4824 | = cast_or_null<CXXConstructorDecl>( |
| 4825 | getDerived().TransformDecl(E->getConstructor())); |
| 4826 | if (!Constructor) |
| 4827 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4829 | bool ArgumentChanged = false; |
| 4830 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4831 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4832 | ArgEnd = E->arg_end(); |
| 4833 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4834 | if (getDerived().DropCallArgument(*Arg)) { |
| 4835 | ArgumentChanged = true; |
| 4836 | break; |
| 4837 | } |
| 4838 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4839 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4840 | if (TransArg.isInvalid()) |
| 4841 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4843 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4844 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4845 | } |
| 4846 | |
| 4847 | if (!getDerived().AlwaysRebuild() && |
| 4848 | T == E->getType() && |
| 4849 | Constructor == E->getConstructor() && |
| 4850 | !ArgumentChanged) |
| 4851 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4852 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4853 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4854 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4855 | move_arg(Args)); |
| 4856 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4857 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4858 | /// \brief Transform a C++ temporary-binding expression. |
| 4859 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4860 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4861 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4862 | template<typename Derived> |
| 4863 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4864 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4865 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4866 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4867 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame^] | 4868 | /// \brief Transform a C++ reference-binding expression. |
| 4869 | /// |
| 4870 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 4871 | /// transform the subexpression and return that. |
| 4872 | template<typename Derived> |
| 4873 | Sema::OwningExprResult |
| 4874 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 4875 | return getDerived().TransformExpr(E->getSubExpr()); |
| 4876 | } |
| 4877 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4878 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4879 | /// be destroyed after the expression is evaluated. |
| 4880 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4881 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4882 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4883 | template<typename Derived> |
| 4884 | Sema::OwningExprResult |
| 4885 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4886 | CXXExprWithTemporaries *E) { |
| 4887 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4888 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4889 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4890 | template<typename Derived> |
| 4891 | Sema::OwningExprResult |
| 4892 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4893 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4895 | QualType T = getDerived().TransformType(E->getType()); |
| 4896 | if (T.isNull()) |
| 4897 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4898 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4899 | CXXConstructorDecl *Constructor |
| 4900 | = cast_or_null<CXXConstructorDecl>( |
| 4901 | getDerived().TransformDecl(E->getConstructor())); |
| 4902 | if (!Constructor) |
| 4903 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | bool ArgumentChanged = false; |
| 4906 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4907 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4908 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4909 | ArgEnd = E->arg_end(); |
| 4910 | Arg != ArgEnd; ++Arg) { |
| 4911 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4912 | if (TransArg.isInvalid()) |
| 4913 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4915 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4916 | Args.push_back((Expr *)TransArg.release()); |
| 4917 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4918 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4919 | if (!getDerived().AlwaysRebuild() && |
| 4920 | T == E->getType() && |
| 4921 | Constructor == E->getConstructor() && |
| 4922 | !ArgumentChanged) |
| 4923 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4924 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4925 | // FIXME: Bogus location information |
| 4926 | SourceLocation CommaLoc; |
| 4927 | if (Args.size() > 1) { |
| 4928 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4929 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4930 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4931 | } |
| 4932 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4933 | T, |
| 4934 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4935 | move_arg(Args), |
| 4936 | &CommaLoc, |
| 4937 | E->getLocEnd()); |
| 4938 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4939 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4940 | template<typename Derived> |
| 4941 | Sema::OwningExprResult |
| 4942 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4943 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4944 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4945 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4946 | if (T.isNull()) |
| 4947 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4949 | bool ArgumentChanged = false; |
| 4950 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4951 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4952 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4953 | ArgEnd = E->arg_end(); |
| 4954 | Arg != ArgEnd; ++Arg) { |
| 4955 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4956 | if (TransArg.isInvalid()) |
| 4957 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4959 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4960 | FakeCommaLocs.push_back( |
| 4961 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4962 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4963 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4964 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4965 | if (!getDerived().AlwaysRebuild() && |
| 4966 | T == E->getTypeAsWritten() && |
| 4967 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | return SemaRef.Owned(E->Retain()); |
| 4969 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4970 | // FIXME: we're faking the locations of the commas |
| 4971 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4972 | T, |
| 4973 | E->getLParenLoc(), |
| 4974 | move_arg(Args), |
| 4975 | FakeCommaLocs.data(), |
| 4976 | E->getRParenLoc()); |
| 4977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4979 | template<typename Derived> |
| 4980 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4981 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4982 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4983 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4984 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4985 | Expr *OldBase; |
| 4986 | QualType BaseType; |
| 4987 | QualType ObjectType; |
| 4988 | if (!E->isImplicitAccess()) { |
| 4989 | OldBase = E->getBase(); |
| 4990 | Base = getDerived().TransformExpr(OldBase); |
| 4991 | if (Base.isInvalid()) |
| 4992 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4994 | // Start the member reference and compute the object's type. |
| 4995 | Sema::TypeTy *ObjectTy = 0; |
| 4996 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4997 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4998 | E->isArrow()? tok::arrow : tok::period, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4999 | ObjectTy); |
| 5000 | if (Base.isInvalid()) |
| 5001 | return SemaRef.ExprError(); |
| 5002 | |
| 5003 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5004 | BaseType = ((Expr*) Base.get())->getType(); |
| 5005 | } else { |
| 5006 | OldBase = 0; |
| 5007 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5008 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5009 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5011 | // Transform the first part of the nested-name-specifier that qualifies |
| 5012 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5013 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5014 | = getDerived().TransformFirstQualifierInScope( |
| 5015 | E->getFirstQualifierFoundInScope(), |
| 5016 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5017 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5018 | NestedNameSpecifier *Qualifier = 0; |
| 5019 | if (E->getQualifier()) { |
| 5020 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5021 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5022 | ObjectType, |
| 5023 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5024 | if (!Qualifier) |
| 5025 | return SemaRef.ExprError(); |
| 5026 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5027 | |
| 5028 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5029 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5030 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5031 | if (!Name) |
| 5032 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5033 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5034 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5035 | // This is a reference to a member without an explicitly-specified |
| 5036 | // template argument list. Optimize for this common case. |
| 5037 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5038 | Base.get() == OldBase && |
| 5039 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5040 | Qualifier == E->getQualifier() && |
| 5041 | Name == E->getMember() && |
| 5042 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5043 | return SemaRef.Owned(E->Retain()); |
| 5044 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5045 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5046 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5047 | E->isArrow(), |
| 5048 | E->getOperatorLoc(), |
| 5049 | Qualifier, |
| 5050 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5051 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5052 | Name, |
| 5053 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5054 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5055 | } |
| 5056 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5057 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5058 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5059 | TemplateArgumentLoc Loc; |
| 5060 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5061 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5062 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5063 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5065 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5066 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | E->isArrow(), |
| 5068 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5069 | Qualifier, |
| 5070 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5071 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5072 | Name, |
| 5073 | E->getMemberLoc(), |
| 5074 | &TransArgs); |
| 5075 | } |
| 5076 | |
| 5077 | template<typename Derived> |
| 5078 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5079 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5080 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5081 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5082 | QualType BaseType; |
| 5083 | if (!Old->isImplicitAccess()) { |
| 5084 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5085 | if (Base.isInvalid()) |
| 5086 | return SemaRef.ExprError(); |
| 5087 | BaseType = ((Expr*) Base.get())->getType(); |
| 5088 | } else { |
| 5089 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5090 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5091 | |
| 5092 | NestedNameSpecifier *Qualifier = 0; |
| 5093 | if (Old->getQualifier()) { |
| 5094 | Qualifier |
| 5095 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 5096 | Old->getQualifierRange()); |
| 5097 | if (Qualifier == 0) |
| 5098 | return SemaRef.ExprError(); |
| 5099 | } |
| 5100 | |
| 5101 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5102 | Sema::LookupOrdinaryName); |
| 5103 | |
| 5104 | // Transform all the decls. |
| 5105 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5106 | E = Old->decls_end(); I != E; ++I) { |
| 5107 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5108 | if (!InstD) { |
| 5109 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5110 | // This can happen because of dependent hiding. |
| 5111 | if (isa<UsingShadowDecl>(*I)) |
| 5112 | continue; |
| 5113 | else |
| 5114 | return SemaRef.ExprError(); |
| 5115 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5116 | |
| 5117 | // Expand using declarations. |
| 5118 | if (isa<UsingDecl>(InstD)) { |
| 5119 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5120 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5121 | E = UD->shadow_end(); I != E; ++I) |
| 5122 | R.addDecl(*I); |
| 5123 | continue; |
| 5124 | } |
| 5125 | |
| 5126 | R.addDecl(InstD); |
| 5127 | } |
| 5128 | |
| 5129 | R.resolveKind(); |
| 5130 | |
| 5131 | TemplateArgumentListInfo TransArgs; |
| 5132 | if (Old->hasExplicitTemplateArgs()) { |
| 5133 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5134 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5135 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5136 | TemplateArgumentLoc Loc; |
| 5137 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5138 | Loc)) |
| 5139 | return SemaRef.ExprError(); |
| 5140 | TransArgs.addArgument(Loc); |
| 5141 | } |
| 5142 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5143 | |
| 5144 | // FIXME: to do this check properly, we will need to preserve the |
| 5145 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5146 | // base (and therefore couldn't do the check) and a |
| 5147 | // nested-name-qualifier (and therefore could do the lookup). |
| 5148 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5149 | |
| 5150 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5151 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5152 | Old->getOperatorLoc(), |
| 5153 | Old->isArrow(), |
| 5154 | Qualifier, |
| 5155 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5156 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5157 | R, |
| 5158 | (Old->hasExplicitTemplateArgs() |
| 5159 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | template<typename Derived> |
| 5163 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5164 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5165 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5168 | template<typename Derived> |
| 5169 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5170 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5171 | // FIXME: poor source location |
| 5172 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5173 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5174 | if (EncodedType.isNull()) |
| 5175 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | if (!getDerived().AlwaysRebuild() && |
| 5178 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | |
| 5181 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5182 | EncodedType, |
| 5183 | E->getRParenLoc()); |
| 5184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5186 | template<typename Derived> |
| 5187 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5188 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5189 | // FIXME: Implement this! |
| 5190 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | template<typename Derived> |
| 5195 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5196 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | template<typename Derived> |
| 5201 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5202 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5203 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | = cast_or_null<ObjCProtocolDecl>( |
| 5205 | getDerived().TransformDecl(E->getProtocol())); |
| 5206 | if (!Protocol) |
| 5207 | return SemaRef.ExprError(); |
| 5208 | |
| 5209 | if (!getDerived().AlwaysRebuild() && |
| 5210 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5211 | return SemaRef.Owned(E->Retain()); |
| 5212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5213 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5214 | E->getAtLoc(), |
| 5215 | /*FIXME:*/E->getAtLoc(), |
| 5216 | /*FIXME:*/E->getAtLoc(), |
| 5217 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | } |
| 5220 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5221 | template<typename Derived> |
| 5222 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5223 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5224 | // FIXME: Implement this! |
| 5225 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5226 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5229 | template<typename Derived> |
| 5230 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5231 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5232 | // FIXME: Implement this! |
| 5233 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5237 | template<typename Derived> |
| 5238 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5239 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5240 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5241 | // FIXME: Implement this! |
| 5242 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5244 | } |
| 5245 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | template<typename Derived> |
| 5247 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5248 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5249 | // FIXME: Implement this! |
| 5250 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5251 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5254 | template<typename Derived> |
| 5255 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5256 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5257 | // FIXME: Implement this! |
| 5258 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5259 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5260 | } |
| 5261 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5262 | template<typename Derived> |
| 5263 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5264 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5265 | bool ArgumentChanged = false; |
| 5266 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5267 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5268 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5269 | if (SubExpr.isInvalid()) |
| 5270 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5272 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5273 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5275 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5276 | if (!getDerived().AlwaysRebuild() && |
| 5277 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | return SemaRef.Owned(E->Retain()); |
| 5279 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5280 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5281 | move_arg(SubExprs), |
| 5282 | E->getRParenLoc()); |
| 5283 | } |
| 5284 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5285 | template<typename Derived> |
| 5286 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5287 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5288 | // FIXME: Implement this! |
| 5289 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5290 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5291 | } |
| 5292 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5293 | template<typename Derived> |
| 5294 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5295 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5296 | // FIXME: Implement this! |
| 5297 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5298 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5299 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5300 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5301 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5302 | // Type reconstruction |
| 5303 | //===----------------------------------------------------------------------===// |
| 5304 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5306 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5307 | SourceLocation Star) { |
| 5308 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5309 | getDerived().getBaseEntity()); |
| 5310 | } |
| 5311 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5312 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5313 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5314 | SourceLocation Star) { |
| 5315 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5316 | getDerived().getBaseEntity()); |
| 5317 | } |
| 5318 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5319 | template<typename Derived> |
| 5320 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5321 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5322 | bool WrittenAsLValue, |
| 5323 | SourceLocation Sigil) { |
| 5324 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5325 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5329 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5330 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5331 | QualType ClassType, |
| 5332 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5333 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5334 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5339 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5340 | SourceLocation Sigil) { |
| 5341 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5342 | getDerived().getBaseEntity()); |
| 5343 | } |
| 5344 | |
| 5345 | template<typename Derived> |
| 5346 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5347 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5348 | ArrayType::ArraySizeModifier SizeMod, |
| 5349 | const llvm::APInt *Size, |
| 5350 | Expr *SizeExpr, |
| 5351 | unsigned IndexTypeQuals, |
| 5352 | SourceRange BracketsRange) { |
| 5353 | if (SizeExpr || !Size) |
| 5354 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5355 | IndexTypeQuals, BracketsRange, |
| 5356 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | |
| 5358 | QualType Types[] = { |
| 5359 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5360 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5361 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5362 | }; |
| 5363 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5364 | QualType SizeType; |
| 5365 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5366 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5367 | SizeType = Types[I]; |
| 5368 | break; |
| 5369 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5370 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5371 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5373 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5377 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5378 | QualType |
| 5379 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5380 | ArrayType::ArraySizeModifier SizeMod, |
| 5381 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5382 | unsigned IndexTypeQuals, |
| 5383 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5385 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5389 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5391 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5392 | unsigned IndexTypeQuals, |
| 5393 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5394 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5395 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5397 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5398 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5399 | QualType |
| 5400 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5401 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5402 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5403 | unsigned IndexTypeQuals, |
| 5404 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5406 | SizeExpr.takeAs<Expr>(), |
| 5407 | IndexTypeQuals, BracketsRange); |
| 5408 | } |
| 5409 | |
| 5410 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | QualType |
| 5412 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5413 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5414 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5415 | unsigned IndexTypeQuals, |
| 5416 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5418 | SizeExpr.takeAs<Expr>(), |
| 5419 | IndexTypeQuals, BracketsRange); |
| 5420 | } |
| 5421 | |
| 5422 | template<typename Derived> |
| 5423 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5424 | unsigned NumElements) { |
| 5425 | // FIXME: semantic checking! |
| 5426 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5428 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5429 | template<typename Derived> |
| 5430 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5431 | unsigned NumElements, |
| 5432 | SourceLocation AttributeLoc) { |
| 5433 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5434 | NumElements, true); |
| 5435 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5437 | AttributeLoc); |
| 5438 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5439 | AttributeLoc); |
| 5440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5442 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5443 | QualType |
| 5444 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5445 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5446 | SourceLocation AttributeLoc) { |
| 5447 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5448 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5450 | template<typename Derived> |
| 5451 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5453 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5454 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5455 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5457 | Quals, |
| 5458 | getDerived().getBaseLocation(), |
| 5459 | getDerived().getBaseEntity()); |
| 5460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5462 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5463 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5464 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5465 | } |
| 5466 | |
| 5467 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5468 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5469 | assert(D && "no decl found"); |
| 5470 | if (D->isInvalidDecl()) return QualType(); |
| 5471 | |
| 5472 | TypeDecl *Ty; |
| 5473 | if (isa<UsingDecl>(D)) { |
| 5474 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5475 | assert(Using->isTypeName() && |
| 5476 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5477 | |
| 5478 | // A valid resolved using typename decl points to exactly one type decl. |
| 5479 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5480 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5481 | |
| 5482 | } else { |
| 5483 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5484 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5485 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5486 | } |
| 5487 | |
| 5488 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5489 | } |
| 5490 | |
| 5491 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5492 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5493 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5494 | } |
| 5495 | |
| 5496 | template<typename Derived> |
| 5497 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5498 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5499 | } |
| 5500 | |
| 5501 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5503 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5504 | } |
| 5505 | |
| 5506 | template<typename Derived> |
| 5507 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5508 | TemplateName Template, |
| 5509 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5510 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5511 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5512 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5513 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5514 | template<typename Derived> |
| 5515 | NestedNameSpecifier * |
| 5516 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5517 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5518 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5519 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5520 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5521 | CXXScopeSpec SS; |
| 5522 | // FIXME: The source location information is all wrong. |
| 5523 | SS.setRange(Range); |
| 5524 | SS.setScopeRep(Prefix); |
| 5525 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5526 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5527 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5528 | ObjectType, |
| 5529 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5530 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | template<typename Derived> |
| 5534 | NestedNameSpecifier * |
| 5535 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5536 | SourceRange Range, |
| 5537 | NamespaceDecl *NS) { |
| 5538 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5539 | } |
| 5540 | |
| 5541 | template<typename Derived> |
| 5542 | NestedNameSpecifier * |
| 5543 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5544 | SourceRange Range, |
| 5545 | bool TemplateKW, |
| 5546 | QualType T) { |
| 5547 | if (T->isDependentType() || T->isRecordType() || |
| 5548 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5549 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5550 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5551 | T.getTypePtr()); |
| 5552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5554 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5555 | return 0; |
| 5556 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5557 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5558 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5559 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5560 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5561 | bool TemplateKW, |
| 5562 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5563 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5564 | Template); |
| 5565 | } |
| 5566 | |
| 5567 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5568 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5569 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5570 | const IdentifierInfo &II, |
| 5571 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5572 | CXXScopeSpec SS; |
| 5573 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5575 | UnqualifiedId Name; |
| 5576 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5577 | return getSema().ActOnDependentTemplateName( |
| 5578 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5579 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5580 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5581 | ObjectType.getAsOpaquePtr(), |
| 5582 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5583 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5584 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5585 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5586 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5587 | TemplateName |
| 5588 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5589 | OverloadedOperatorKind Operator, |
| 5590 | QualType ObjectType) { |
| 5591 | CXXScopeSpec SS; |
| 5592 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5593 | SS.setScopeRep(Qualifier); |
| 5594 | UnqualifiedId Name; |
| 5595 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5596 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5597 | Operator, SymbolLocations); |
| 5598 | return getSema().ActOnDependentTemplateName( |
| 5599 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5600 | SS, |
| 5601 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5602 | ObjectType.getAsOpaquePtr(), |
| 5603 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5604 | .template getAsVal<TemplateName>(); |
| 5605 | } |
| 5606 | |
| 5607 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5608 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5609 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5610 | SourceLocation OpLoc, |
| 5611 | ExprArg Callee, |
| 5612 | ExprArg First, |
| 5613 | ExprArg Second) { |
| 5614 | Expr *FirstExpr = (Expr *)First.get(); |
| 5615 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5616 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5617 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5618 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5619 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5620 | if (Op == OO_Subscript) { |
| 5621 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5622 | !SecondExpr->getType()->isOverloadableType()) |
| 5623 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5624 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5625 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5626 | } else if (Op == OO_Arrow) { |
| 5627 | // -> is never a builtin operation. |
| 5628 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5629 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5630 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5631 | // The argument is not of overloadable type, so try to create a |
| 5632 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5633 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5634 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5635 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5636 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5637 | } |
| 5638 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5639 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5640 | !SecondExpr->getType()->isOverloadableType()) { |
| 5641 | // Neither of the arguments is an overloadable type, so try to |
| 5642 | // create a built-in binary operation. |
| 5643 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5644 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5645 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5646 | if (Result.isInvalid()) |
| 5647 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5648 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5649 | First.release(); |
| 5650 | Second.release(); |
| 5651 | return move(Result); |
| 5652 | } |
| 5653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5654 | |
| 5655 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5657 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5659 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5660 | assert(ULE->requiresADL()); |
| 5661 | |
| 5662 | // FIXME: Do we have to check |
| 5663 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5664 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5665 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5666 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5669 | // Add any functions found via argument-dependent lookup. |
| 5670 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5671 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5672 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5673 | // Create the overloaded operator invocation for unary operators. |
| 5674 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5675 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5676 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5677 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5678 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5679 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5680 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5681 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5682 | OpLoc, |
| 5683 | move(First), |
| 5684 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5685 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5687 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5688 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5691 | if (Result.isInvalid()) |
| 5692 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | First.release(); |
| 5695 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5696 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5697 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5698 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5699 | } // end namespace clang |
| 5700 | |
| 5701 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |