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. |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 432 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | /// \brief Build a new extended vector type given the element type and |
| 435 | /// number of elements. |
| 436 | /// |
| 437 | /// By default, performs semantic analysis when building the vector type. |
| 438 | /// Subclasses may override this routine to provide different behavior. |
| 439 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 440 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | |
| 442 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 443 | /// given the element type and number of elements. |
| 444 | /// |
| 445 | /// By default, performs semantic analysis when building the vector type. |
| 446 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 448 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 449 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 451 | /// \brief Build a new function type. |
| 452 | /// |
| 453 | /// By default, performs semantic analysis when building the function type. |
| 454 | /// Subclasses may override this routine to provide different behavior. |
| 455 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 457 | unsigned NumParamTypes, |
| 458 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 459 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 460 | /// \brief Build a new unprototyped function type. |
| 461 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 462 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 463 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 464 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 465 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 466 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 467 | /// \brief Build a new typedef type. |
| 468 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 469 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 470 | } |
| 471 | |
| 472 | /// \brief Build a new class/struct/union type. |
| 473 | QualType RebuildRecordType(RecordDecl *Record) { |
| 474 | return SemaRef.Context.getTypeDeclType(Record); |
| 475 | } |
| 476 | |
| 477 | /// \brief Build a new Enum type. |
| 478 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 479 | return SemaRef.Context.getTypeDeclType(Enum); |
| 480 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 481 | |
| 482 | /// \brief Build a new elaborated type. |
| 483 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 484 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
| 487 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 488 | /// |
| 489 | /// By default, performs semantic analysis when building the typeof type. |
| 490 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 491 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 492 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 494 | /// |
| 495 | /// By default, builds a new TypeOfType with the given underlying type. |
| 496 | QualType RebuildTypeOfType(QualType Underlying); |
| 497 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 499 | /// |
| 500 | /// By default, performs semantic analysis when building the decltype type. |
| 501 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 502 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 504 | /// \brief Build a new template specialization type. |
| 505 | /// |
| 506 | /// By default, performs semantic analysis when building the template |
| 507 | /// specialization type. Subclasses may override this routine to provide |
| 508 | /// different behavior. |
| 509 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 510 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 511 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 513 | /// \brief Build a new qualified name type. |
| 514 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | /// By default, builds a new QualifiedNameType type from the |
| 516 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// this routine to provide different behavior. |
| 518 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 519 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | |
| 522 | /// \brief Build a new typename type that refers to a template-id. |
| 523 | /// |
| 524 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// different behavior. |
| 527 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 528 | if (NNS->isDependent()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 532 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | |
| 535 | /// \brief Build a new typename type that refers to an identifier. |
| 536 | /// |
| 537 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 539 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 541 | const IdentifierInfo *Id, |
| 542 | SourceRange SR) { |
| 543 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 545 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 546 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 547 | /// identifier that names the next step in the nested-name-specifier. |
| 548 | /// |
| 549 | /// By default, performs semantic analysis when building the new |
| 550 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 551 | /// different behavior. |
| 552 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 553 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 554 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 555 | QualType ObjectType, |
| 556 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 557 | |
| 558 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 559 | /// namespace named in the next step in the nested-name-specifier. |
| 560 | /// |
| 561 | /// By default, performs semantic analysis when building the new |
| 562 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 563 | /// different behavior. |
| 564 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 565 | SourceRange Range, |
| 566 | NamespaceDecl *NS); |
| 567 | |
| 568 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 569 | /// type named in the next step in the nested-name-specifier. |
| 570 | /// |
| 571 | /// By default, performs semantic analysis when building the new |
| 572 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 573 | /// different behavior. |
| 574 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 575 | SourceRange Range, |
| 576 | bool TemplateKW, |
| 577 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 578 | |
| 579 | /// \brief Build a new template name given a nested name specifier, a flag |
| 580 | /// indicating whether the "template" keyword was provided, and the template |
| 581 | /// that the template name refers to. |
| 582 | /// |
| 583 | /// By default, builds the new template name directly. Subclasses may override |
| 584 | /// this routine to provide different behavior. |
| 585 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 586 | bool TemplateKW, |
| 587 | TemplateDecl *Template); |
| 588 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 589 | /// \brief Build a new template name given a nested name specifier and the |
| 590 | /// name that is referred to as a template. |
| 591 | /// |
| 592 | /// By default, performs semantic analysis to determine whether the name can |
| 593 | /// be resolved to a specific template, then builds the appropriate kind of |
| 594 | /// template name. Subclasses may override this routine to provide different |
| 595 | /// behavior. |
| 596 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 597 | const IdentifierInfo &II, |
| 598 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 599 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 600 | /// \brief Build a new template name given a nested name specifier and the |
| 601 | /// overloaded operator name that is referred to as a template. |
| 602 | /// |
| 603 | /// By default, performs semantic analysis to determine whether the name can |
| 604 | /// be resolved to a specific template, then builds the appropriate kind of |
| 605 | /// template name. Subclasses may override this routine to provide different |
| 606 | /// behavior. |
| 607 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 608 | OverloadedOperatorKind Operator, |
| 609 | QualType ObjectType); |
| 610 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 611 | /// \brief Build a new compound statement. |
| 612 | /// |
| 613 | /// By default, performs semantic analysis to build the new statement. |
| 614 | /// Subclasses may override this routine to provide different behavior. |
| 615 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 616 | MultiStmtArg Statements, |
| 617 | SourceLocation RBraceLoc, |
| 618 | bool IsStmtExpr) { |
| 619 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 620 | IsStmtExpr); |
| 621 | } |
| 622 | |
| 623 | /// \brief Build a new case statement. |
| 624 | /// |
| 625 | /// By default, performs semantic analysis to build the new statement. |
| 626 | /// Subclasses may override this routine to provide different behavior. |
| 627 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 628 | ExprArg LHS, |
| 629 | SourceLocation EllipsisLoc, |
| 630 | ExprArg RHS, |
| 631 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 633 | ColonLoc); |
| 634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 636 | /// \brief Attach the body to a new case statement. |
| 637 | /// |
| 638 | /// By default, performs semantic analysis to build the new statement. |
| 639 | /// Subclasses may override this routine to provide different behavior. |
| 640 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 641 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 642 | return move(S); |
| 643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 645 | /// \brief Build a new default statement. |
| 646 | /// |
| 647 | /// By default, performs semantic analysis to build the new statement. |
| 648 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 650 | SourceLocation ColonLoc, |
| 651 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 653 | /*CurScope=*/0); |
| 654 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 656 | /// \brief Build a new label statement. |
| 657 | /// |
| 658 | /// By default, performs semantic analysis to build the new statement. |
| 659 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 661 | IdentifierInfo *Id, |
| 662 | SourceLocation ColonLoc, |
| 663 | StmtArg SubStmt) { |
| 664 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 665 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 667 | /// \brief Build a new "if" statement. |
| 668 | /// |
| 669 | /// By default, performs semantic analysis to build the new statement. |
| 670 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 672 | VarDecl *CondVar, StmtArg Then, |
| 673 | SourceLocation ElseLoc, StmtArg Else) { |
| 674 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 675 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 678 | /// \brief Start building a new switch statement. |
| 679 | /// |
| 680 | /// By default, performs semantic analysis to build the new statement. |
| 681 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 682 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 683 | VarDecl *CondVar) { |
| 684 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 685 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 687 | /// \brief Attach the body to the switch statement. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis to build the new statement. |
| 690 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 692 | StmtArg Switch, StmtArg Body) { |
| 693 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 694 | move(Body)); |
| 695 | } |
| 696 | |
| 697 | /// \brief Build a new while statement. |
| 698 | /// |
| 699 | /// By default, performs semantic analysis to build the new statement. |
| 700 | /// Subclasses may override this routine to provide different behavior. |
| 701 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 702 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 703 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 704 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 705 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 706 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 707 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 709 | /// \brief Build a new do-while statement. |
| 710 | /// |
| 711 | /// By default, performs semantic analysis to build the new statement. |
| 712 | /// Subclasses may override this routine to provide different behavior. |
| 713 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 714 | SourceLocation WhileLoc, |
| 715 | SourceLocation LParenLoc, |
| 716 | ExprArg Cond, |
| 717 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 719 | move(Cond), RParenLoc); |
| 720 | } |
| 721 | |
| 722 | /// \brief Build a new for statement. |
| 723 | /// |
| 724 | /// By default, performs semantic analysis to build the new statement. |
| 725 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 728 | StmtArg Init, Sema::FullExprArg Cond, |
| 729 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 730 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 731 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 732 | DeclPtrTy::make(CondVar), |
| 733 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | /// \brief Build a new goto statement. |
| 737 | /// |
| 738 | /// By default, performs semantic analysis to build the new statement. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
| 740 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 741 | SourceLocation LabelLoc, |
| 742 | LabelStmt *Label) { |
| 743 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 744 | } |
| 745 | |
| 746 | /// \brief Build a new indirect goto statement. |
| 747 | /// |
| 748 | /// By default, performs semantic analysis to build the new statement. |
| 749 | /// Subclasses may override this routine to provide different behavior. |
| 750 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 751 | SourceLocation StarLoc, |
| 752 | ExprArg Target) { |
| 753 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 754 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 756 | /// \brief Build a new return statement. |
| 757 | /// |
| 758 | /// By default, performs semantic analysis to build the new statement. |
| 759 | /// Subclasses may override this routine to provide different behavior. |
| 760 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 761 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 763 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 764 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 766 | /// \brief Build a new declaration statement. |
| 767 | /// |
| 768 | /// By default, performs semantic analysis to build the new statement. |
| 769 | /// Subclasses may override this routine to provide different behavior. |
| 770 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 772 | SourceLocation EndLoc) { |
| 773 | return getSema().Owned( |
| 774 | new (getSema().Context) DeclStmt( |
| 775 | DeclGroupRef::Create(getSema().Context, |
| 776 | Decls, NumDecls), |
| 777 | StartLoc, EndLoc)); |
| 778 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 780 | /// \brief Build a new inline asm statement. |
| 781 | /// |
| 782 | /// By default, performs semantic analysis to build the new statement. |
| 783 | /// Subclasses may override this routine to provide different behavior. |
| 784 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 785 | bool IsSimple, |
| 786 | bool IsVolatile, |
| 787 | unsigned NumOutputs, |
| 788 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 789 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 790 | MultiExprArg Constraints, |
| 791 | MultiExprArg Exprs, |
| 792 | ExprArg AsmString, |
| 793 | MultiExprArg Clobbers, |
| 794 | SourceLocation RParenLoc, |
| 795 | bool MSAsm) { |
| 796 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 797 | NumInputs, Names, move(Constraints), |
| 798 | move(Exprs), move(AsmString), move(Clobbers), |
| 799 | RParenLoc, MSAsm); |
| 800 | } |
| 801 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 802 | /// \brief Build a new C++ exception declaration. |
| 803 | /// |
| 804 | /// By default, performs semantic analysis to build the new decaration. |
| 805 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 807 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 808 | IdentifierInfo *Name, |
| 809 | SourceLocation Loc, |
| 810 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 812 | TypeRange); |
| 813 | } |
| 814 | |
| 815 | /// \brief Build a new C++ catch statement. |
| 816 | /// |
| 817 | /// By default, performs semantic analysis to build the new statement. |
| 818 | /// Subclasses may override this routine to provide different behavior. |
| 819 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 820 | VarDecl *ExceptionDecl, |
| 821 | StmtArg Handler) { |
| 822 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 823 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 824 | Handler.takeAs<Stmt>())); |
| 825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | /// \brief Build a new C++ try statement. |
| 828 | /// |
| 829 | /// By default, performs semantic analysis to build the new statement. |
| 830 | /// Subclasses may override this routine to provide different behavior. |
| 831 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 832 | StmtArg TryBlock, |
| 833 | MultiStmtArg Handlers) { |
| 834 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 835 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 836 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 837 | /// \brief Build a new expression that references a declaration. |
| 838 | /// |
| 839 | /// By default, performs semantic analysis to build the new expression. |
| 840 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 841 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 842 | LookupResult &R, |
| 843 | bool RequiresADL) { |
| 844 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 845 | } |
| 846 | |
| 847 | |
| 848 | /// \brief Build a new expression that references a declaration. |
| 849 | /// |
| 850 | /// By default, performs semantic analysis to build the new expression. |
| 851 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 852 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 853 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 854 | ValueDecl *VD, SourceLocation Loc, |
| 855 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 856 | CXXScopeSpec SS; |
| 857 | SS.setScopeRep(Qualifier); |
| 858 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 859 | |
| 860 | // FIXME: loses template args. |
| 861 | |
| 862 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 863 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 864 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 865 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 866 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 867 | /// By default, performs semantic analysis to build the new expression. |
| 868 | /// Subclasses may override this routine to provide different behavior. |
| 869 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 870 | SourceLocation RParen) { |
| 871 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 872 | } |
| 873 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 874 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 875 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 876 | /// By default, performs semantic analysis to build the new expression. |
| 877 | /// Subclasses may override this routine to provide different behavior. |
| 878 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 879 | SourceLocation OperatorLoc, |
| 880 | bool isArrow, |
| 881 | SourceLocation DestroyedTypeLoc, |
| 882 | QualType DestroyedType, |
| 883 | NestedNameSpecifier *Qualifier, |
| 884 | SourceRange QualifierRange) { |
| 885 | CXXScopeSpec SS; |
| 886 | if (Qualifier) { |
| 887 | SS.setRange(QualifierRange); |
| 888 | SS.setScopeRep(Qualifier); |
| 889 | } |
| 890 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 891 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 892 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 894 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 895 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 896 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 897 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 898 | OperatorLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 899 | SS, /*FIXME: FirstQualifier*/ 0, |
| 900 | Name, DestroyedTypeLoc, |
| 901 | /*TemplateArgs*/ 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 904 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 906 | /// By default, performs semantic analysis to build the new expression. |
| 907 | /// Subclasses may override this routine to provide different behavior. |
| 908 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 909 | UnaryOperator::Opcode Opc, |
| 910 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 911 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 914 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | /// By default, performs semantic analysis to build the new expression. |
| 917 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 918 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 919 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 921 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 925 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 926 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 927 | /// By default, performs semantic analysis to build the new expression. |
| 928 | /// Subclasses may override this routine to provide different behavior. |
| 929 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 930 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 932 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 933 | OpLoc, isSizeOf, R); |
| 934 | if (Result.isInvalid()) |
| 935 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 937 | SubExpr.release(); |
| 938 | return move(Result); |
| 939 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 940 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 941 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 942 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 943 | /// By default, performs semantic analysis to build the new expression. |
| 944 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 945 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 946 | SourceLocation LBracketLoc, |
| 947 | ExprArg RHS, |
| 948 | SourceLocation RBracketLoc) { |
| 949 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 950 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 951 | RBracketLoc); |
| 952 | } |
| 953 | |
| 954 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 956 | /// By default, performs semantic analysis to build the new expression. |
| 957 | /// Subclasses may override this routine to provide different behavior. |
| 958 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 959 | MultiExprArg Args, |
| 960 | SourceLocation *CommaLocs, |
| 961 | SourceLocation RParenLoc) { |
| 962 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 963 | move(Args), CommaLocs, RParenLoc); |
| 964 | } |
| 965 | |
| 966 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 968 | /// By default, performs semantic analysis to build the new expression. |
| 969 | /// Subclasses may override this routine to provide different behavior. |
| 970 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 972 | NestedNameSpecifier *Qualifier, |
| 973 | SourceRange QualifierRange, |
| 974 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 975 | ValueDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 976 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 977 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 978 | if (!Member->getDeclName()) { |
| 979 | // We have a reference to an unnamed field. |
| 980 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 982 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 983 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 984 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 985 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 987 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 988 | Member, MemberLoc, |
| 989 | cast<FieldDecl>(Member)->getType()); |
| 990 | return getSema().Owned(ME); |
| 991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 993 | CXXScopeSpec SS; |
| 994 | if (Qualifier) { |
| 995 | SS.setRange(QualifierRange); |
| 996 | SS.setScopeRep(Qualifier); |
| 997 | } |
| 998 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 999 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1000 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1001 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1002 | Sema::LookupMemberName); |
| 1003 | R.addDecl(Member); |
| 1004 | R.resolveKind(); |
| 1005 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1006 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1007 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1008 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1009 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1012 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | /// By default, performs semantic analysis to build the new expression. |
| 1015 | /// Subclasses may override this routine to provide different behavior. |
| 1016 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1017 | BinaryOperator::Opcode Opc, |
| 1018 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1019 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1020 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// By default, performs semantic analysis to build the new expression. |
| 1026 | /// Subclasses may override this routine to provide different behavior. |
| 1027 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1028 | SourceLocation QuestionLoc, |
| 1029 | ExprArg LHS, |
| 1030 | SourceLocation ColonLoc, |
| 1031 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1032 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1033 | move(LHS), move(RHS)); |
| 1034 | } |
| 1035 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1036 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1037 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1038 | /// By default, performs semantic analysis to build the new expression. |
| 1039 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1040 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1041 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | SourceLocation RParenLoc, |
| 1043 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1044 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1045 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1048 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | /// By default, performs semantic analysis to build the new expression. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
| 1052 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1053 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | SourceLocation RParenLoc, |
| 1055 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1056 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1057 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1060 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | /// By default, performs semantic analysis to build the new expression. |
| 1063 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1065 | SourceLocation OpLoc, |
| 1066 | SourceLocation AccessorLoc, |
| 1067 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1068 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1069 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1070 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1071 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1072 | OpLoc, /*IsArrow*/ false, |
| 1073 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1074 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1075 | AccessorLoc, |
| 1076 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1079 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1081 | /// By default, performs semantic analysis to build the new expression. |
| 1082 | /// Subclasses may override this routine to provide different behavior. |
| 1083 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1084 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1085 | SourceLocation RBraceLoc, |
| 1086 | QualType ResultTy) { |
| 1087 | OwningExprResult Result |
| 1088 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1089 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1090 | return move(Result); |
| 1091 | |
| 1092 | // Patch in the result type we were given, which may have been computed |
| 1093 | // when the initial InitListExpr was built. |
| 1094 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1095 | ILE->setType(ResultTy); |
| 1096 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | /// By default, performs semantic analysis to build the new expression. |
| 1102 | /// Subclasses may override this routine to provide different behavior. |
| 1103 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1104 | MultiExprArg ArrayExprs, |
| 1105 | SourceLocation EqualOrColonLoc, |
| 1106 | bool GNUSyntax, |
| 1107 | ExprArg Init) { |
| 1108 | OwningExprResult Result |
| 1109 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1110 | move(Init)); |
| 1111 | if (Result.isInvalid()) |
| 1112 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1114 | ArrayExprs.release(); |
| 1115 | return move(Result); |
| 1116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// By default, builds the implicit value initialization without performing |
| 1121 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1122 | /// different behavior. |
| 1123 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1124 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1129 | /// By default, performs semantic analysis to build the new expression. |
| 1130 | /// Subclasses may override this routine to provide different behavior. |
| 1131 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1132 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1133 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1134 | RParenLoc); |
| 1135 | } |
| 1136 | |
| 1137 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// By default, performs semantic analysis to build the new expression. |
| 1140 | /// Subclasses may override this routine to provide different behavior. |
| 1141 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1142 | MultiExprArg SubExprs, |
| 1143 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1144 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1145 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1148 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | /// |
| 1150 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1151 | /// rather than attempting to map the label statement itself. |
| 1152 | /// Subclasses may override this routine to provide different behavior. |
| 1153 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1154 | SourceLocation LabelLoc, |
| 1155 | LabelStmt *Label) { |
| 1156 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1159 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1160 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1161 | /// By default, performs semantic analysis to build the new expression. |
| 1162 | /// Subclasses may override this routine to provide different behavior. |
| 1163 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1164 | StmtArg SubStmt, |
| 1165 | SourceLocation RParenLoc) { |
| 1166 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1167 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1169 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1170 | /// |
| 1171 | /// By default, performs semantic analysis to build the new expression. |
| 1172 | /// Subclasses may override this routine to provide different behavior. |
| 1173 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1174 | QualType T1, QualType T2, |
| 1175 | SourceLocation RParenLoc) { |
| 1176 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1177 | T1.getAsOpaquePtr(), |
| 1178 | T2.getAsOpaquePtr(), |
| 1179 | RParenLoc); |
| 1180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1182 | /// \brief Build a new __builtin_choose_expr expression. |
| 1183 | /// |
| 1184 | /// By default, performs semantic analysis to build the new expression. |
| 1185 | /// Subclasses may override this routine to provide different behavior. |
| 1186 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1187 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1188 | SourceLocation RParenLoc) { |
| 1189 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1190 | move(Cond), move(LHS), move(RHS), |
| 1191 | RParenLoc); |
| 1192 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | /// \brief Build a new overloaded operator call expression. |
| 1195 | /// |
| 1196 | /// By default, performs semantic analysis to build the new expression. |
| 1197 | /// The semantic analysis provides the behavior of template instantiation, |
| 1198 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1200 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1201 | /// provide different behavior. |
| 1202 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1203 | SourceLocation OpLoc, |
| 1204 | ExprArg Callee, |
| 1205 | ExprArg First, |
| 1206 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | |
| 1208 | /// \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] | 1209 | /// reinterpret_cast. |
| 1210 | /// |
| 1211 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | /// Subclasses may override this routine to provide different behavior. |
| 1214 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1215 | Stmt::StmtClass Class, |
| 1216 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1217 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | SourceLocation RAngleLoc, |
| 1219 | SourceLocation LParenLoc, |
| 1220 | ExprArg SubExpr, |
| 1221 | SourceLocation RParenLoc) { |
| 1222 | switch (Class) { |
| 1223 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1224 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | move(SubExpr), RParenLoc); |
| 1227 | |
| 1228 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1229 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1231 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1233 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1234 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | RAngleLoc, LParenLoc, |
| 1236 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1239 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1240 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | default: |
| 1245 | assert(false && "Invalid C++ named cast"); |
| 1246 | break; |
| 1247 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1248 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1249 | return getSema().ExprError(); |
| 1250 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1251 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1252 | /// \brief Build a new C++ static_cast expression. |
| 1253 | /// |
| 1254 | /// By default, performs semantic analysis to build the new expression. |
| 1255 | /// Subclasses may override this routine to provide different behavior. |
| 1256 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1257 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1258 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1259 | SourceLocation RAngleLoc, |
| 1260 | SourceLocation LParenLoc, |
| 1261 | ExprArg SubExpr, |
| 1262 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1263 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1264 | TInfo, move(SubExpr), |
| 1265 | SourceRange(LAngleLoc, RAngleLoc), |
| 1266 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /// \brief Build a new C++ dynamic_cast expression. |
| 1270 | /// |
| 1271 | /// By default, performs semantic analysis to build the new expression. |
| 1272 | /// Subclasses may override this routine to provide different behavior. |
| 1273 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1274 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1275 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1276 | SourceLocation RAngleLoc, |
| 1277 | SourceLocation LParenLoc, |
| 1278 | ExprArg SubExpr, |
| 1279 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1280 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1281 | TInfo, move(SubExpr), |
| 1282 | SourceRange(LAngleLoc, RAngleLoc), |
| 1283 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1287 | /// |
| 1288 | /// By default, performs semantic analysis to build the new expression. |
| 1289 | /// Subclasses may override this routine to provide different behavior. |
| 1290 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1291 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1292 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1293 | SourceLocation RAngleLoc, |
| 1294 | SourceLocation LParenLoc, |
| 1295 | ExprArg SubExpr, |
| 1296 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1297 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1298 | TInfo, move(SubExpr), |
| 1299 | SourceRange(LAngleLoc, RAngleLoc), |
| 1300 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /// \brief Build a new C++ const_cast expression. |
| 1304 | /// |
| 1305 | /// By default, performs semantic analysis to build the new expression. |
| 1306 | /// Subclasses may override this routine to provide different behavior. |
| 1307 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1308 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1309 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | SourceLocation RAngleLoc, |
| 1311 | SourceLocation LParenLoc, |
| 1312 | ExprArg SubExpr, |
| 1313 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1314 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1315 | TInfo, move(SubExpr), |
| 1316 | SourceRange(LAngleLoc, RAngleLoc), |
| 1317 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1319 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1320 | /// \brief Build a new C++ functional-style cast expression. |
| 1321 | /// |
| 1322 | /// By default, performs semantic analysis to build the new expression. |
| 1323 | /// Subclasses may override this routine to provide different behavior. |
| 1324 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1325 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | SourceLocation LParenLoc, |
| 1327 | ExprArg SubExpr, |
| 1328 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1329 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1331 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1333 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1334 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | RParenLoc); |
| 1336 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | /// \brief Build a new C++ typeid(type) expression. |
| 1339 | /// |
| 1340 | /// By default, performs semantic analysis to build the new expression. |
| 1341 | /// Subclasses may override this routine to provide different behavior. |
| 1342 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1343 | SourceLocation LParenLoc, |
| 1344 | QualType T, |
| 1345 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | T.getAsOpaquePtr(), RParenLoc); |
| 1348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | /// \brief Build a new C++ typeid(expr) expression. |
| 1351 | /// |
| 1352 | /// By default, performs semantic analysis to build the new expression. |
| 1353 | /// Subclasses may override this routine to provide different behavior. |
| 1354 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1355 | SourceLocation LParenLoc, |
| 1356 | ExprArg Operand, |
| 1357 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1358 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1359 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1360 | RParenLoc); |
| 1361 | if (Result.isInvalid()) |
| 1362 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1363 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1364 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1365 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | /// \brief Build a new C++ "this" expression. |
| 1369 | /// |
| 1370 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1374 | QualType ThisType, |
| 1375 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1377 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1378 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /// \brief Build a new C++ throw expression. |
| 1382 | /// |
| 1383 | /// By default, performs semantic analysis to build the new expression. |
| 1384 | /// Subclasses may override this routine to provide different behavior. |
| 1385 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1386 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1387 | } |
| 1388 | |
| 1389 | /// \brief Build a new C++ default-argument expression. |
| 1390 | /// |
| 1391 | /// By default, builds a new default-argument expression, which does not |
| 1392 | /// require any semantic analysis. Subclasses may override this routine to |
| 1393 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1394 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1395 | ParmVarDecl *Param) { |
| 1396 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1397 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /// \brief Build a new C++ zero-initialization expression. |
| 1401 | /// |
| 1402 | /// By default, performs semantic analysis to build the new expression. |
| 1403 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | SourceLocation LParenLoc, |
| 1406 | QualType T, |
| 1407 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1409 | T.getAsOpaquePtr(), LParenLoc, |
| 1410 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1411 | 0, RParenLoc); |
| 1412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | /// \brief Build a new C++ "new" expression. |
| 1415 | /// |
| 1416 | /// By default, performs semantic analysis to build the new expression. |
| 1417 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1419 | bool UseGlobal, |
| 1420 | SourceLocation PlacementLParen, |
| 1421 | MultiExprArg PlacementArgs, |
| 1422 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | QualType AllocType, |
| 1425 | SourceLocation TypeLoc, |
| 1426 | SourceRange TypeRange, |
| 1427 | ExprArg ArraySize, |
| 1428 | SourceLocation ConstructorLParen, |
| 1429 | MultiExprArg ConstructorArgs, |
| 1430 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1431 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1432 | PlacementLParen, |
| 1433 | move(PlacementArgs), |
| 1434 | PlacementRParen, |
| 1435 | ParenTypeId, |
| 1436 | AllocType, |
| 1437 | TypeLoc, |
| 1438 | TypeRange, |
| 1439 | move(ArraySize), |
| 1440 | ConstructorLParen, |
| 1441 | move(ConstructorArgs), |
| 1442 | ConstructorRParen); |
| 1443 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1445 | /// \brief Build a new C++ "delete" expression. |
| 1446 | /// |
| 1447 | /// By default, performs semantic analysis to build the new expression. |
| 1448 | /// Subclasses may override this routine to provide different behavior. |
| 1449 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1450 | bool IsGlobalDelete, |
| 1451 | bool IsArrayForm, |
| 1452 | ExprArg Operand) { |
| 1453 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1454 | move(Operand)); |
| 1455 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | /// \brief Build a new unary type trait expression. |
| 1458 | /// |
| 1459 | /// By default, performs semantic analysis to build the new expression. |
| 1460 | /// Subclasses may override this routine to provide different behavior. |
| 1461 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1462 | SourceLocation StartLoc, |
| 1463 | SourceLocation LParenLoc, |
| 1464 | QualType T, |
| 1465 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1466 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1467 | T.getAsOpaquePtr(), RParenLoc); |
| 1468 | } |
| 1469 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1470 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | /// expression. |
| 1472 | /// |
| 1473 | /// By default, performs semantic analysis to build the new expression. |
| 1474 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1475 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1476 | SourceRange QualifierRange, |
| 1477 | DeclarationName Name, |
| 1478 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1479 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | CXXScopeSpec SS; |
| 1481 | SS.setRange(QualifierRange); |
| 1482 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1483 | |
| 1484 | if (TemplateArgs) |
| 1485 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1486 | *TemplateArgs); |
| 1487 | |
| 1488 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /// \brief Build a new template-id expression. |
| 1492 | /// |
| 1493 | /// By default, performs semantic analysis to build the new expression. |
| 1494 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1495 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1496 | LookupResult &R, |
| 1497 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1498 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1499 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /// \brief Build a new object-construction expression. |
| 1503 | /// |
| 1504 | /// By default, performs semantic analysis to build the new expression. |
| 1505 | /// Subclasses may override this routine to provide different behavior. |
| 1506 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1507 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1508 | CXXConstructorDecl *Constructor, |
| 1509 | bool IsElidable, |
| 1510 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1511 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1512 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1513 | ConvertedArgs)) |
| 1514 | return getSema().ExprError(); |
| 1515 | |
| 1516 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1517 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | /// \brief Build a new object-construction expression. |
| 1521 | /// |
| 1522 | /// By default, performs semantic analysis to build the new expression. |
| 1523 | /// Subclasses may override this routine to provide different behavior. |
| 1524 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1525 | QualType T, |
| 1526 | SourceLocation LParenLoc, |
| 1527 | MultiExprArg Args, |
| 1528 | SourceLocation *Commas, |
| 1529 | SourceLocation RParenLoc) { |
| 1530 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1531 | T.getAsOpaquePtr(), |
| 1532 | LParenLoc, |
| 1533 | move(Args), |
| 1534 | Commas, |
| 1535 | RParenLoc); |
| 1536 | } |
| 1537 | |
| 1538 | /// \brief Build a new object-construction expression. |
| 1539 | /// |
| 1540 | /// By default, performs semantic analysis to build the new expression. |
| 1541 | /// Subclasses may override this routine to provide different behavior. |
| 1542 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1543 | QualType T, |
| 1544 | SourceLocation LParenLoc, |
| 1545 | MultiExprArg Args, |
| 1546 | SourceLocation *Commas, |
| 1547 | SourceLocation RParenLoc) { |
| 1548 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1549 | /*FIXME*/LParenLoc), |
| 1550 | T.getAsOpaquePtr(), |
| 1551 | LParenLoc, |
| 1552 | move(Args), |
| 1553 | Commas, |
| 1554 | RParenLoc); |
| 1555 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | /// \brief Build a new member reference expression. |
| 1558 | /// |
| 1559 | /// By default, performs semantic analysis to build the new expression. |
| 1560 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1561 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1562 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1563 | bool IsArrow, |
| 1564 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1565 | NestedNameSpecifier *Qualifier, |
| 1566 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1567 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1569 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1570 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1572 | SS.setRange(QualifierRange); |
| 1573 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1574 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1575 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1576 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1577 | SS, FirstQualifierInScope, |
| 1578 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1581 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1582 | /// |
| 1583 | /// By default, performs semantic analysis to build the new expression. |
| 1584 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1585 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1586 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1587 | SourceLocation OperatorLoc, |
| 1588 | bool IsArrow, |
| 1589 | NestedNameSpecifier *Qualifier, |
| 1590 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1591 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1592 | LookupResult &R, |
| 1593 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1594 | CXXScopeSpec SS; |
| 1595 | SS.setRange(QualifierRange); |
| 1596 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1597 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1598 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1599 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1600 | SS, FirstQualifierInScope, |
| 1601 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1602 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1603 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | /// \brief Build a new Objective-C @encode expression. |
| 1605 | /// |
| 1606 | /// By default, performs semantic analysis to build the new expression. |
| 1607 | /// Subclasses may override this routine to provide different behavior. |
| 1608 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1609 | QualType T, |
| 1610 | SourceLocation RParenLoc) { |
| 1611 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1612 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | |
| 1615 | /// \brief Build a new Objective-C protocol expression. |
| 1616 | /// |
| 1617 | /// By default, performs semantic analysis to build the new expression. |
| 1618 | /// Subclasses may override this routine to provide different behavior. |
| 1619 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1620 | SourceLocation AtLoc, |
| 1621 | SourceLocation ProtoLoc, |
| 1622 | SourceLocation LParenLoc, |
| 1623 | SourceLocation RParenLoc) { |
| 1624 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1625 | Protocol->getIdentifier(), |
| 1626 | AtLoc, |
| 1627 | ProtoLoc, |
| 1628 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1631 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1632 | /// \brief Build a new shuffle vector expression. |
| 1633 | /// |
| 1634 | /// By default, performs semantic analysis to build the new expression. |
| 1635 | /// Subclasses may override this routine to provide different behavior. |
| 1636 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1637 | MultiExprArg SubExprs, |
| 1638 | SourceLocation RParenLoc) { |
| 1639 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1641 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1642 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1643 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1644 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | // Build a reference to the __builtin_shufflevector builtin |
| 1647 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1650 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1651 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | |
| 1653 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | unsigned NumSubExprs = SubExprs.size(); |
| 1655 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1656 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1657 | Subs, NumSubExprs, |
| 1658 | Builtin->getResultType(), |
| 1659 | RParenLoc); |
| 1660 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1661 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1662 | // Type-check the __builtin_shufflevector expression. |
| 1663 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1664 | if (Result.isInvalid()) |
| 1665 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1667 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1670 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1672 | template<typename Derived> |
| 1673 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1674 | if (!S) |
| 1675 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1677 | switch (S->getStmtClass()) { |
| 1678 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1680 | // Transform individual statement nodes |
| 1681 | #define STMT(Node, Parent) \ |
| 1682 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1683 | #define EXPR(Node, Parent) |
| 1684 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1686 | // Transform expressions by calling TransformExpr. |
| 1687 | #define STMT(Node, Parent) |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1688 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1689 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1690 | #include "clang/AST/StmtNodes.def" |
| 1691 | { |
| 1692 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1693 | if (E.isInvalid()) |
| 1694 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1696 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1697 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1700 | return SemaRef.Owned(S->Retain()); |
| 1701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | |
| 1703 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1704 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1705 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1706 | if (!E) |
| 1707 | return SemaRef.Owned(E); |
| 1708 | |
| 1709 | switch (E->getStmtClass()) { |
| 1710 | case Stmt::NoStmtClass: break; |
| 1711 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1712 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1713 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1714 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1715 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1722 | NestedNameSpecifier * |
| 1723 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1724 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1725 | QualType ObjectType, |
| 1726 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1727 | if (!NNS) |
| 1728 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1730 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1731 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1732 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1734 | ObjectType, |
| 1735 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1736 | if (!Prefix) |
| 1737 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1738 | |
| 1739 | // 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] | 1740 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1741 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1742 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1745 | switch (NNS->getKind()) { |
| 1746 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1747 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1748 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1749 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1750 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1751 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | |
| 1753 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1754 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1755 | ObjectType, |
| 1756 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1758 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1760 | = cast_or_null<NamespaceDecl>( |
| 1761 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1762 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1763 | Prefix == NNS->getPrefix() && |
| 1764 | NS == NNS->getAsNamespace()) |
| 1765 | return NNS; |
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 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1770 | case NestedNameSpecifier::Global: |
| 1771 | // There is no meaningful transformation that one could perform on the |
| 1772 | // global scope. |
| 1773 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1775 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1776 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1777 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1778 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1779 | if (T.isNull()) |
| 1780 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1781 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1782 | if (!getDerived().AlwaysRebuild() && |
| 1783 | Prefix == NNS->getPrefix() && |
| 1784 | T == QualType(NNS->getAsType(), 0)) |
| 1785 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | |
| 1787 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1788 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1789 | T); |
| 1790 | } |
| 1791 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1793 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1799 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1800 | SourceLocation Loc, |
| 1801 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1802 | if (!Name) |
| 1803 | return Name; |
| 1804 | |
| 1805 | switch (Name.getNameKind()) { |
| 1806 | case DeclarationName::Identifier: |
| 1807 | case DeclarationName::ObjCZeroArgSelector: |
| 1808 | case DeclarationName::ObjCOneArgSelector: |
| 1809 | case DeclarationName::ObjCMultiArgSelector: |
| 1810 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1811 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1812 | case DeclarationName::CXXUsingDirective: |
| 1813 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1815 | case DeclarationName::CXXConstructorName: |
| 1816 | case DeclarationName::CXXDestructorName: |
| 1817 | case DeclarationName::CXXConversionFunctionName: { |
| 1818 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1819 | QualType T; |
| 1820 | if (!ObjectType.isNull() && |
| 1821 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1822 | TemplateSpecializationType *SpecType |
| 1823 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1824 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1825 | } else |
| 1826 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1827 | if (T.isNull()) |
| 1828 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1830 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1832 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1833 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1836 | return DeclarationName(); |
| 1837 | } |
| 1838 | |
| 1839 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1841 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1842 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1843 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1845 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1846 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1847 | if (!NNS) |
| 1848 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1852 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1853 | if (!TransTemplate) |
| 1854 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1856 | if (!getDerived().AlwaysRebuild() && |
| 1857 | NNS == QTN->getQualifier() && |
| 1858 | TransTemplate == Template) |
| 1859 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1861 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1862 | TransTemplate); |
| 1863 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1865 | // These should be getting filtered out before they make it into the AST. |
| 1866 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1867 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1869 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1871 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1872 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1873 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1876 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1877 | NNS == DTN->getQualifier() && |
| 1878 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1879 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1881 | if (DTN->isIdentifier()) |
| 1882 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1883 | ObjectType); |
| 1884 | |
| 1885 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1886 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1889 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1890 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1891 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1892 | if (!TransTemplate) |
| 1893 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1895 | if (!getDerived().AlwaysRebuild() && |
| 1896 | TransTemplate == Template) |
| 1897 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1899 | return TemplateName(TransTemplate); |
| 1900 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1902 | // These should be getting filtered out before they reach the AST. |
| 1903 | assert(false && "overloaded function decl survived to here"); |
| 1904 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1908 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1909 | const TemplateArgument &Arg, |
| 1910 | TemplateArgumentLoc &Output) { |
| 1911 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1912 | switch (Arg.getKind()) { |
| 1913 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1914 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1915 | break; |
| 1916 | |
| 1917 | case TemplateArgument::Type: |
| 1918 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1919 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1920 | |
| 1921 | break; |
| 1922 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1923 | case TemplateArgument::Template: |
| 1924 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1925 | break; |
| 1926 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1927 | case TemplateArgument::Expression: |
| 1928 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1929 | break; |
| 1930 | |
| 1931 | case TemplateArgument::Declaration: |
| 1932 | case TemplateArgument::Integral: |
| 1933 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1934 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1935 | break; |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | template<typename Derived> |
| 1940 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1941 | const TemplateArgumentLoc &Input, |
| 1942 | TemplateArgumentLoc &Output) { |
| 1943 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1944 | switch (Arg.getKind()) { |
| 1945 | case TemplateArgument::Null: |
| 1946 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1947 | Output = Input; |
| 1948 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1950 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1951 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1952 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1953 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1954 | |
| 1955 | DI = getDerived().TransformType(DI); |
| 1956 | if (!DI) return true; |
| 1957 | |
| 1958 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1959 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1962 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1963 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1964 | DeclarationName Name; |
| 1965 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1966 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1967 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1968 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1969 | if (!D) return true; |
| 1970 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1971 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1972 | if (SourceExpr) { |
| 1973 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1974 | Action::Unevaluated); |
| 1975 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1976 | if (E.isInvalid()) |
| 1977 | SourceExpr = NULL; |
| 1978 | else { |
| 1979 | SourceExpr = E.takeAs<Expr>(); |
| 1980 | SourceExpr->Retain(); |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1985 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1988 | case TemplateArgument::Template: { |
| 1989 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1990 | TemplateName Template |
| 1991 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1992 | if (Template.isNull()) |
| 1993 | return true; |
| 1994 | |
| 1995 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1996 | Input.getTemplateQualifierRange(), |
| 1997 | Input.getTemplateNameLoc()); |
| 1998 | return false; |
| 1999 | } |
| 2000 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2001 | case TemplateArgument::Expression: { |
| 2002 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2004 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2006 | Expr *InputExpr = Input.getSourceExpression(); |
| 2007 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2008 | |
| 2009 | Sema::OwningExprResult E |
| 2010 | = getDerived().TransformExpr(InputExpr); |
| 2011 | if (E.isInvalid()) return true; |
| 2012 | |
| 2013 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2014 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2015 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2016 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2017 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2019 | case TemplateArgument::Pack: { |
| 2020 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2021 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2023 | AEnd = Arg.pack_end(); |
| 2024 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2026 | // FIXME: preserve source information here when we start |
| 2027 | // caring about parameter packs. |
| 2028 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2029 | TemplateArgumentLoc InputArg; |
| 2030 | TemplateArgumentLoc OutputArg; |
| 2031 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2032 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2033 | return true; |
| 2034 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2035 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2036 | } |
| 2037 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2038 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2039 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2040 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2041 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2042 | } |
| 2043 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2045 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2046 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2049 | //===----------------------------------------------------------------------===// |
| 2050 | // Type transformation |
| 2051 | //===----------------------------------------------------------------------===// |
| 2052 | |
| 2053 | template<typename Derived> |
| 2054 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2055 | if (getDerived().AlreadyTransformed(T)) |
| 2056 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2057 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2058 | // Temporary workaround. All of these transformations should |
| 2059 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2060 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2061 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2062 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2063 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2064 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2065 | if (!NewDI) |
| 2066 | return QualType(); |
| 2067 | |
| 2068 | return NewDI->getType(); |
| 2069 | } |
| 2070 | |
| 2071 | template<typename Derived> |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2072 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2073 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2074 | return DI; |
| 2075 | |
| 2076 | TypeLocBuilder TLB; |
| 2077 | |
| 2078 | TypeLoc TL = DI->getTypeLoc(); |
| 2079 | TLB.reserve(TL.getFullDataSize()); |
| 2080 | |
| 2081 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2082 | if (Result.isNull()) |
| 2083 | return 0; |
| 2084 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2085 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | template<typename Derived> |
| 2089 | QualType |
| 2090 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2091 | switch (T.getTypeLocClass()) { |
| 2092 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2093 | #define TYPELOC(CLASS, PARENT) \ |
| 2094 | case TypeLoc::CLASS: \ |
| 2095 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2096 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2097 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2098 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2099 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2100 | return QualType(); |
| 2101 | } |
| 2102 | |
| 2103 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2104 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2105 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2106 | /// types). This is the right thing for template instantiation, but |
| 2107 | /// probably not for other clients. |
| 2108 | template<typename Derived> |
| 2109 | QualType |
| 2110 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2111 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2112 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2113 | |
| 2114 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2115 | if (Result.isNull()) |
| 2116 | return QualType(); |
| 2117 | |
| 2118 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2119 | // FIXME: this is the right thing for template instantiation, but |
| 2120 | // probably not for other clients. |
| 2121 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2122 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2123 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2124 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2125 | |
| 2126 | TLB.push<QualifiedTypeLoc>(Result); |
| 2127 | |
| 2128 | // No location information to preserve. |
| 2129 | |
| 2130 | return Result; |
| 2131 | } |
| 2132 | |
| 2133 | template <class TyLoc> static inline |
| 2134 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2135 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2136 | NewT.setNameLoc(T.getNameLoc()); |
| 2137 | return T.getType(); |
| 2138 | } |
| 2139 | |
| 2140 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2141 | // the equivalent template version work. |
| 2142 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2143 | QualType PointeeType \ |
| 2144 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2145 | if (PointeeType.isNull()) \ |
| 2146 | return QualType(); \ |
| 2147 | \ |
| 2148 | QualType Result = TL.getType(); \ |
| 2149 | if (getDerived().AlwaysRebuild() || \ |
| 2150 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2151 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2152 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2153 | if (Result.isNull()) \ |
| 2154 | return QualType(); \ |
| 2155 | } \ |
| 2156 | \ |
| 2157 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2158 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2159 | \ |
| 2160 | return Result; \ |
| 2161 | } while(0) |
| 2162 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2163 | template<typename Derived> |
| 2164 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2165 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2166 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2167 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2168 | if (T.needsExtraLocalData()) |
| 2169 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2170 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2171 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2172 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2173 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2174 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2175 | ComplexTypeLoc T) { |
| 2176 | // FIXME: recurse? |
| 2177 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2179 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2180 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2181 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2182 | PointerTypeLoc TL) { |
| 2183 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | |
| 2186 | template<typename Derived> |
| 2187 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2188 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2189 | BlockPointerTypeLoc TL) { |
| 2190 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2193 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2194 | /// don't care whether the type itself is an l-value type or an r-value |
| 2195 | /// type; we only care if the type was *written* as an l-value type |
| 2196 | /// or an r-value type. |
| 2197 | template<typename Derived> |
| 2198 | QualType |
| 2199 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2200 | ReferenceTypeLoc TL) { |
| 2201 | const ReferenceType *T = TL.getTypePtr(); |
| 2202 | |
| 2203 | // Note that this works with the pointee-as-written. |
| 2204 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2205 | if (PointeeType.isNull()) |
| 2206 | return QualType(); |
| 2207 | |
| 2208 | QualType Result = TL.getType(); |
| 2209 | if (getDerived().AlwaysRebuild() || |
| 2210 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2211 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2212 | T->isSpelledAsLValue(), |
| 2213 | TL.getSigilLoc()); |
| 2214 | if (Result.isNull()) |
| 2215 | return QualType(); |
| 2216 | } |
| 2217 | |
| 2218 | // r-value references can be rebuilt as l-value references. |
| 2219 | ReferenceTypeLoc NewTL; |
| 2220 | if (isa<LValueReferenceType>(Result)) |
| 2221 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2222 | else |
| 2223 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2224 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2225 | |
| 2226 | return Result; |
| 2227 | } |
| 2228 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2229 | template<typename Derived> |
| 2230 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2231 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2232 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2233 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2236 | template<typename Derived> |
| 2237 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2238 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2239 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2240 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2242 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2243 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2244 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2245 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2246 | MemberPointerTypeLoc TL) { |
| 2247 | MemberPointerType *T = TL.getTypePtr(); |
| 2248 | |
| 2249 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2250 | if (PointeeType.isNull()) |
| 2251 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2253 | // TODO: preserve source information for this. |
| 2254 | QualType ClassType |
| 2255 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2256 | if (ClassType.isNull()) |
| 2257 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2258 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2259 | QualType Result = TL.getType(); |
| 2260 | if (getDerived().AlwaysRebuild() || |
| 2261 | PointeeType != T->getPointeeType() || |
| 2262 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2263 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2264 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2265 | if (Result.isNull()) |
| 2266 | return QualType(); |
| 2267 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2268 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2269 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2270 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2271 | |
| 2272 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2275 | template<typename Derived> |
| 2276 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2277 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2278 | ConstantArrayTypeLoc TL) { |
| 2279 | ConstantArrayType *T = TL.getTypePtr(); |
| 2280 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2281 | if (ElementType.isNull()) |
| 2282 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2283 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2284 | QualType Result = TL.getType(); |
| 2285 | if (getDerived().AlwaysRebuild() || |
| 2286 | ElementType != T->getElementType()) { |
| 2287 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2288 | T->getSizeModifier(), |
| 2289 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2290 | T->getIndexTypeCVRQualifiers(), |
| 2291 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2292 | if (Result.isNull()) |
| 2293 | return QualType(); |
| 2294 | } |
| 2295 | |
| 2296 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2297 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2298 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2299 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2300 | Expr *Size = TL.getSizeExpr(); |
| 2301 | if (Size) { |
| 2302 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2303 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2304 | } |
| 2305 | NewTL.setSizeExpr(Size); |
| 2306 | |
| 2307 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2308 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2310 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2311 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2312 | TypeLocBuilder &TLB, |
| 2313 | IncompleteArrayTypeLoc TL) { |
| 2314 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2315 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2316 | if (ElementType.isNull()) |
| 2317 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2318 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2319 | QualType Result = TL.getType(); |
| 2320 | if (getDerived().AlwaysRebuild() || |
| 2321 | ElementType != T->getElementType()) { |
| 2322 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2323 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2324 | T->getIndexTypeCVRQualifiers(), |
| 2325 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2326 | if (Result.isNull()) |
| 2327 | return QualType(); |
| 2328 | } |
| 2329 | |
| 2330 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2331 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2332 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2333 | NewTL.setSizeExpr(0); |
| 2334 | |
| 2335 | return Result; |
| 2336 | } |
| 2337 | |
| 2338 | template<typename Derived> |
| 2339 | QualType |
| 2340 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2341 | VariableArrayTypeLoc TL) { |
| 2342 | VariableArrayType *T = TL.getTypePtr(); |
| 2343 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2344 | if (ElementType.isNull()) |
| 2345 | return QualType(); |
| 2346 | |
| 2347 | // Array bounds are not potentially evaluated contexts |
| 2348 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2349 | |
| 2350 | Sema::OwningExprResult SizeResult |
| 2351 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2352 | if (SizeResult.isInvalid()) |
| 2353 | return QualType(); |
| 2354 | |
| 2355 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2356 | |
| 2357 | QualType Result = TL.getType(); |
| 2358 | if (getDerived().AlwaysRebuild() || |
| 2359 | ElementType != T->getElementType() || |
| 2360 | Size != T->getSizeExpr()) { |
| 2361 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2362 | T->getSizeModifier(), |
| 2363 | move(SizeResult), |
| 2364 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2365 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2366 | if (Result.isNull()) |
| 2367 | return QualType(); |
| 2368 | } |
| 2369 | else SizeResult.take(); |
| 2370 | |
| 2371 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2372 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2373 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2374 | NewTL.setSizeExpr(Size); |
| 2375 | |
| 2376 | return Result; |
| 2377 | } |
| 2378 | |
| 2379 | template<typename Derived> |
| 2380 | QualType |
| 2381 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2382 | DependentSizedArrayTypeLoc TL) { |
| 2383 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2384 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2385 | if (ElementType.isNull()) |
| 2386 | return QualType(); |
| 2387 | |
| 2388 | // Array bounds are not potentially evaluated contexts |
| 2389 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2390 | |
| 2391 | Sema::OwningExprResult SizeResult |
| 2392 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2393 | if (SizeResult.isInvalid()) |
| 2394 | return QualType(); |
| 2395 | |
| 2396 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2397 | |
| 2398 | QualType Result = TL.getType(); |
| 2399 | if (getDerived().AlwaysRebuild() || |
| 2400 | ElementType != T->getElementType() || |
| 2401 | Size != T->getSizeExpr()) { |
| 2402 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2403 | T->getSizeModifier(), |
| 2404 | move(SizeResult), |
| 2405 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2406 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2407 | if (Result.isNull()) |
| 2408 | return QualType(); |
| 2409 | } |
| 2410 | else SizeResult.take(); |
| 2411 | |
| 2412 | // We might have any sort of array type now, but fortunately they |
| 2413 | // all have the same location layout. |
| 2414 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2415 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2416 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2417 | NewTL.setSizeExpr(Size); |
| 2418 | |
| 2419 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2420 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2421 | |
| 2422 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2423 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2424 | TypeLocBuilder &TLB, |
| 2425 | DependentSizedExtVectorTypeLoc TL) { |
| 2426 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2427 | |
| 2428 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2429 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2430 | if (ElementType.isNull()) |
| 2431 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2432 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2433 | // Vector sizes are not potentially evaluated contexts |
| 2434 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2435 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2436 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2437 | if (Size.isInvalid()) |
| 2438 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2440 | QualType Result = TL.getType(); |
| 2441 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2442 | ElementType != T->getElementType() || |
| 2443 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2444 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2445 | move(Size), |
| 2446 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2447 | if (Result.isNull()) |
| 2448 | return QualType(); |
| 2449 | } |
| 2450 | else Size.take(); |
| 2451 | |
| 2452 | // Result might be dependent or not. |
| 2453 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2454 | DependentSizedExtVectorTypeLoc NewTL |
| 2455 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2456 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2457 | } else { |
| 2458 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2459 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2460 | } |
| 2461 | |
| 2462 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2463 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2464 | |
| 2465 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2466 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2467 | VectorTypeLoc TL) { |
| 2468 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2469 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2470 | if (ElementType.isNull()) |
| 2471 | return QualType(); |
| 2472 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2473 | QualType Result = TL.getType(); |
| 2474 | if (getDerived().AlwaysRebuild() || |
| 2475 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2476 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2477 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2478 | if (Result.isNull()) |
| 2479 | return QualType(); |
| 2480 | } |
| 2481 | |
| 2482 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2483 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2484 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2485 | return Result; |
| 2486 | } |
| 2487 | |
| 2488 | template<typename Derived> |
| 2489 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2490 | ExtVectorTypeLoc TL) { |
| 2491 | VectorType *T = TL.getTypePtr(); |
| 2492 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2493 | if (ElementType.isNull()) |
| 2494 | return QualType(); |
| 2495 | |
| 2496 | QualType Result = TL.getType(); |
| 2497 | if (getDerived().AlwaysRebuild() || |
| 2498 | ElementType != T->getElementType()) { |
| 2499 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2500 | T->getNumElements(), |
| 2501 | /*FIXME*/ SourceLocation()); |
| 2502 | if (Result.isNull()) |
| 2503 | return QualType(); |
| 2504 | } |
| 2505 | |
| 2506 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2507 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2508 | |
| 2509 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2510 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2511 | |
| 2512 | template<typename Derived> |
| 2513 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2514 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2515 | FunctionProtoTypeLoc TL) { |
| 2516 | FunctionProtoType *T = TL.getTypePtr(); |
| 2517 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2518 | if (ResultType.isNull()) |
| 2519 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2520 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2521 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2522 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2523 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2524 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2525 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2526 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2527 | QualType NewType; |
| 2528 | ParmVarDecl *NewParm; |
| 2529 | |
| 2530 | if (OldParm) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2531 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2532 | assert(OldDI->getType() == T->getArgType(i)); |
| 2533 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2534 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2535 | if (!NewDI) |
| 2536 | return QualType(); |
| 2537 | |
| 2538 | if (NewDI == OldDI) |
| 2539 | NewParm = OldParm; |
| 2540 | else |
| 2541 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2542 | OldParm->getDeclContext(), |
| 2543 | OldParm->getLocation(), |
| 2544 | OldParm->getIdentifier(), |
| 2545 | NewDI->getType(), |
| 2546 | NewDI, |
| 2547 | OldParm->getStorageClass(), |
| 2548 | /* DefArg */ NULL); |
| 2549 | NewType = NewParm->getType(); |
| 2550 | |
| 2551 | // Deal with the possibility that we don't have a parameter |
| 2552 | // declaration for this parameter. |
| 2553 | } else { |
| 2554 | NewParm = 0; |
| 2555 | |
| 2556 | QualType OldType = T->getArgType(i); |
| 2557 | NewType = getDerived().TransformType(OldType); |
| 2558 | if (NewType.isNull()) |
| 2559 | return QualType(); |
| 2560 | } |
| 2561 | |
| 2562 | ParamTypes.push_back(NewType); |
| 2563 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2566 | QualType Result = TL.getType(); |
| 2567 | if (getDerived().AlwaysRebuild() || |
| 2568 | ResultType != T->getResultType() || |
| 2569 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2570 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2571 | ParamTypes.data(), |
| 2572 | ParamTypes.size(), |
| 2573 | T->isVariadic(), |
| 2574 | T->getTypeQuals()); |
| 2575 | if (Result.isNull()) |
| 2576 | return QualType(); |
| 2577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2579 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2580 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2581 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2582 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2583 | NewTL.setArg(i, ParamDecls[i]); |
| 2584 | |
| 2585 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2586 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2588 | template<typename Derived> |
| 2589 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2590 | TypeLocBuilder &TLB, |
| 2591 | FunctionNoProtoTypeLoc TL) { |
| 2592 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2593 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2594 | if (ResultType.isNull()) |
| 2595 | return QualType(); |
| 2596 | |
| 2597 | QualType Result = TL.getType(); |
| 2598 | if (getDerived().AlwaysRebuild() || |
| 2599 | ResultType != T->getResultType()) |
| 2600 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2601 | |
| 2602 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2603 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2604 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2605 | |
| 2606 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2608 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2609 | template<typename Derived> QualType |
| 2610 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2611 | UnresolvedUsingTypeLoc TL) { |
| 2612 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2613 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2614 | if (!D) |
| 2615 | return QualType(); |
| 2616 | |
| 2617 | QualType Result = TL.getType(); |
| 2618 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2619 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2620 | if (Result.isNull()) |
| 2621 | return QualType(); |
| 2622 | } |
| 2623 | |
| 2624 | // We might get an arbitrary type spec type back. We should at |
| 2625 | // least always get a type spec type, though. |
| 2626 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2627 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2628 | |
| 2629 | return Result; |
| 2630 | } |
| 2631 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2632 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2633 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2634 | TypedefTypeLoc TL) { |
| 2635 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2636 | TypedefDecl *Typedef |
| 2637 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2638 | if (!Typedef) |
| 2639 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2640 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2641 | QualType Result = TL.getType(); |
| 2642 | if (getDerived().AlwaysRebuild() || |
| 2643 | Typedef != T->getDecl()) { |
| 2644 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2645 | if (Result.isNull()) |
| 2646 | return QualType(); |
| 2647 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2648 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2650 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2651 | |
| 2652 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2654 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2655 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2656 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2657 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2658 | // typeof expressions are not potentially evaluated contexts |
| 2659 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2660 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2661 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2662 | if (E.isInvalid()) |
| 2663 | return QualType(); |
| 2664 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2665 | QualType Result = TL.getType(); |
| 2666 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2667 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2669 | if (Result.isNull()) |
| 2670 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2671 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2672 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2673 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2674 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2675 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2676 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2677 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2678 | |
| 2679 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2681 | |
| 2682 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2684 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2685 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2686 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2687 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2688 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2689 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2691 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2692 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2693 | if (Result.isNull()) |
| 2694 | return QualType(); |
| 2695 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2696 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2697 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2698 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2699 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2700 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2701 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2702 | |
| 2703 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2704 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2705 | |
| 2706 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2707 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2708 | DecltypeTypeLoc TL) { |
| 2709 | DecltypeType *T = TL.getTypePtr(); |
| 2710 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2711 | // decltype expressions are not potentially evaluated contexts |
| 2712 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2714 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2715 | if (E.isInvalid()) |
| 2716 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2717 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2718 | QualType Result = TL.getType(); |
| 2719 | if (getDerived().AlwaysRebuild() || |
| 2720 | E.get() != T->getUnderlyingExpr()) { |
| 2721 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2722 | if (Result.isNull()) |
| 2723 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2724 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2725 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2726 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2727 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2728 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2729 | |
| 2730 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2734 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2735 | RecordTypeLoc TL) { |
| 2736 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2737 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2738 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2739 | if (!Record) |
| 2740 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2742 | QualType Result = TL.getType(); |
| 2743 | if (getDerived().AlwaysRebuild() || |
| 2744 | Record != T->getDecl()) { |
| 2745 | Result = getDerived().RebuildRecordType(Record); |
| 2746 | if (Result.isNull()) |
| 2747 | return QualType(); |
| 2748 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2749 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2751 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2752 | |
| 2753 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2754 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2755 | |
| 2756 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2757 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2758 | EnumTypeLoc TL) { |
| 2759 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2760 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2762 | if (!Enum) |
| 2763 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2764 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2765 | QualType Result = TL.getType(); |
| 2766 | if (getDerived().AlwaysRebuild() || |
| 2767 | Enum != T->getDecl()) { |
| 2768 | Result = getDerived().RebuildEnumType(Enum); |
| 2769 | if (Result.isNull()) |
| 2770 | return QualType(); |
| 2771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2772 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2773 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2774 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2775 | |
| 2776 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2777 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2778 | |
| 2779 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2781 | ElaboratedTypeLoc TL) { |
| 2782 | ElaboratedType *T = TL.getTypePtr(); |
| 2783 | |
| 2784 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2785 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2786 | if (Underlying.isNull()) |
| 2787 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2788 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2789 | QualType Result = TL.getType(); |
| 2790 | if (getDerived().AlwaysRebuild() || |
| 2791 | Underlying != T->getUnderlyingType()) { |
| 2792 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2793 | if (Result.isNull()) |
| 2794 | return QualType(); |
| 2795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2796 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2798 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2799 | |
| 2800 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2801 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | |
| 2803 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2804 | template<typename Derived> |
| 2805 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2806 | TypeLocBuilder &TLB, |
| 2807 | TemplateTypeParmTypeLoc TL) { |
| 2808 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2809 | } |
| 2810 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2812 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2813 | TypeLocBuilder &TLB, |
| 2814 | SubstTemplateTypeParmTypeLoc TL) { |
| 2815 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2819 | inline QualType |
| 2820 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2821 | TypeLocBuilder &TLB, |
| 2822 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2823 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2824 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2825 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2826 | template<typename Derived> |
| 2827 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2828 | const TemplateSpecializationType *TST, |
| 2829 | QualType ObjectType) { |
| 2830 | // FIXME: this entire method is a temporary workaround; callers |
| 2831 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2832 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2833 | // Fake up a TemplateSpecializationTypeLoc. |
| 2834 | TypeLocBuilder TLB; |
| 2835 | TemplateSpecializationTypeLoc TL |
| 2836 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2837 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2838 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2839 | |
| 2840 | TL.setTemplateNameLoc(BaseLoc); |
| 2841 | TL.setLAngleLoc(BaseLoc); |
| 2842 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2843 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2844 | const TemplateArgument &TA = TST->getArg(i); |
| 2845 | TemplateArgumentLoc TAL; |
| 2846 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2847 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2848 | } |
| 2849 | |
| 2850 | TypeLocBuilder IgnoredTLB; |
| 2851 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2855 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2856 | TypeLocBuilder &TLB, |
| 2857 | TemplateSpecializationTypeLoc TL, |
| 2858 | QualType ObjectType) { |
| 2859 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2860 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2861 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2862 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2863 | if (Template.isNull()) |
| 2864 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2865 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2866 | TemplateArgumentListInfo NewTemplateArgs; |
| 2867 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2868 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2869 | |
| 2870 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2871 | TemplateArgumentLoc Loc; |
| 2872 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2873 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2874 | NewTemplateArgs.addArgument(Loc); |
| 2875 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2876 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2877 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2878 | |
| 2879 | QualType Result = |
| 2880 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2881 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2882 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2883 | |
| 2884 | if (!Result.isNull()) { |
| 2885 | TemplateSpecializationTypeLoc NewTL |
| 2886 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2887 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2888 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2889 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2890 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2891 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2894 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2896 | |
| 2897 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2898 | QualType |
| 2899 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2900 | QualifiedNameTypeLoc TL) { |
| 2901 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2902 | NestedNameSpecifier *NNS |
| 2903 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2904 | SourceRange()); |
| 2905 | if (!NNS) |
| 2906 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2908 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2909 | if (Named.isNull()) |
| 2910 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2911 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2912 | QualType Result = TL.getType(); |
| 2913 | if (getDerived().AlwaysRebuild() || |
| 2914 | NNS != T->getQualifier() || |
| 2915 | Named != T->getNamedType()) { |
| 2916 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2917 | if (Result.isNull()) |
| 2918 | return QualType(); |
| 2919 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2920 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2921 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2922 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2923 | |
| 2924 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2925 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2926 | |
| 2927 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2928 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2929 | TypenameTypeLoc TL) { |
| 2930 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2931 | |
| 2932 | /* FIXME: preserve source information better than this */ |
| 2933 | SourceRange SR(TL.getNameLoc()); |
| 2934 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2935 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2936 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2937 | if (!NNS) |
| 2938 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2939 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2940 | QualType Result; |
| 2941 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2942 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2944 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2945 | if (NewTemplateId.isNull()) |
| 2946 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2947 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2948 | if (!getDerived().AlwaysRebuild() && |
| 2949 | NNS == T->getQualifier() && |
| 2950 | NewTemplateId == QualType(TemplateId, 0)) |
| 2951 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2952 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2953 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2954 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2955 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2956 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2957 | if (Result.isNull()) |
| 2958 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2959 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2960 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2961 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2962 | |
| 2963 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2964 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2965 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2966 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2967 | QualType |
| 2968 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2969 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2970 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2971 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2973 | |
| 2974 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2975 | QualType |
| 2976 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2977 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2978 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2979 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2982 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2983 | // Statement transformation |
| 2984 | //===----------------------------------------------------------------------===// |
| 2985 | template<typename Derived> |
| 2986 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2987 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2988 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | template<typename Derived> |
| 2992 | Sema::OwningStmtResult |
| 2993 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2994 | return getDerived().TransformCompoundStmt(S, false); |
| 2995 | } |
| 2996 | |
| 2997 | template<typename Derived> |
| 2998 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2999 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3000 | bool IsStmtExpr) { |
| 3001 | bool SubStmtChanged = false; |
| 3002 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3003 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3004 | B != BEnd; ++B) { |
| 3005 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3006 | if (Result.isInvalid()) |
| 3007 | return getSema().StmtError(); |
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 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3010 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3011 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3012 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3013 | if (!getDerived().AlwaysRebuild() && |
| 3014 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3015 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3016 | |
| 3017 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3018 | move_arg(Statements), |
| 3019 | S->getRBracLoc(), |
| 3020 | IsStmtExpr); |
| 3021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3023 | template<typename Derived> |
| 3024 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3025 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3026 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3027 | { |
| 3028 | // The case value expressions are not potentially evaluated. |
| 3029 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3030 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3031 | // Transform the left-hand case value. |
| 3032 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3033 | if (LHS.isInvalid()) |
| 3034 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3036 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3037 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3038 | if (RHS.isInvalid()) |
| 3039 | return SemaRef.StmtError(); |
| 3040 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3041 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3042 | // Build the case statement. |
| 3043 | // Case statements are always rebuilt so that they will attached to their |
| 3044 | // transformed switch statement. |
| 3045 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3046 | move(LHS), |
| 3047 | S->getEllipsisLoc(), |
| 3048 | move(RHS), |
| 3049 | S->getColonLoc()); |
| 3050 | if (Case.isInvalid()) |
| 3051 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3053 | // Transform the statement following the case |
| 3054 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3055 | if (SubStmt.isInvalid()) |
| 3056 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3058 | // Attach the body to the case statement |
| 3059 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3060 | } |
| 3061 | |
| 3062 | template<typename Derived> |
| 3063 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3064 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3065 | // Transform the statement following the default case |
| 3066 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3067 | if (SubStmt.isInvalid()) |
| 3068 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3069 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3070 | // Default statements are always rebuilt |
| 3071 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3072 | move(SubStmt)); |
| 3073 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3074 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3075 | template<typename Derived> |
| 3076 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3078 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3079 | if (SubStmt.isInvalid()) |
| 3080 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3082 | // FIXME: Pass the real colon location in. |
| 3083 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3084 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3085 | move(SubStmt)); |
| 3086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3088 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3089 | Sema::OwningStmtResult |
| 3090 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3091 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3092 | OwningExprResult Cond(SemaRef); |
| 3093 | VarDecl *ConditionVar = 0; |
| 3094 | if (S->getConditionVariable()) { |
| 3095 | ConditionVar |
| 3096 | = cast_or_null<VarDecl>( |
| 3097 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3098 | if (!ConditionVar) |
| 3099 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3100 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3101 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3102 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3103 | if (Cond.isInvalid()) |
| 3104 | return SemaRef.StmtError(); |
| 3105 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3106 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3107 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3108 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3109 | // Transform the "then" branch. |
| 3110 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3111 | if (Then.isInvalid()) |
| 3112 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3113 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3114 | // Transform the "else" branch. |
| 3115 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3116 | if (Else.isInvalid()) |
| 3117 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3118 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3119 | if (!getDerived().AlwaysRebuild() && |
| 3120 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3121 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | Then.get() == S->getThen() && |
| 3123 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | return SemaRef.Owned(S->Retain()); |
| 3125 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3126 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3127 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | template<typename Derived> |
| 3132 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3134 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3135 | OwningExprResult Cond(SemaRef); |
| 3136 | VarDecl *ConditionVar = 0; |
| 3137 | if (S->getConditionVariable()) { |
| 3138 | ConditionVar |
| 3139 | = cast_or_null<VarDecl>( |
| 3140 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3141 | if (!ConditionVar) |
| 3142 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3143 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3144 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3145 | |
| 3146 | if (Cond.isInvalid()) |
| 3147 | return SemaRef.StmtError(); |
| 3148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3150 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3151 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3152 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3153 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3154 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3155 | if (Switch.isInvalid()) |
| 3156 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3157 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3158 | // Transform the body of the switch statement. |
| 3159 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3160 | if (Body.isInvalid()) |
| 3161 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | // Complete the switch statement. |
| 3164 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3165 | move(Body)); |
| 3166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3168 | template<typename Derived> |
| 3169 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3170 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3171 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3172 | OwningExprResult Cond(SemaRef); |
| 3173 | VarDecl *ConditionVar = 0; |
| 3174 | if (S->getConditionVariable()) { |
| 3175 | ConditionVar |
| 3176 | = cast_or_null<VarDecl>( |
| 3177 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3178 | if (!ConditionVar) |
| 3179 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3180 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3181 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3182 | |
| 3183 | if (Cond.isInvalid()) |
| 3184 | return SemaRef.StmtError(); |
| 3185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3187 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3189 | // Transform the body |
| 3190 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3191 | if (Body.isInvalid()) |
| 3192 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3193 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3194 | if (!getDerived().AlwaysRebuild() && |
| 3195 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3196 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3197 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | return SemaRef.Owned(S->Retain()); |
| 3199 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3200 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3201 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3202 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | template<typename Derived> |
| 3205 | Sema::OwningStmtResult |
| 3206 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3207 | // Transform the condition |
| 3208 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3209 | if (Cond.isInvalid()) |
| 3210 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3211 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3212 | // Transform the body |
| 3213 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3214 | if (Body.isInvalid()) |
| 3215 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3216 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3217 | if (!getDerived().AlwaysRebuild() && |
| 3218 | Cond.get() == S->getCond() && |
| 3219 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | return SemaRef.Owned(S->Retain()); |
| 3221 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3222 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3223 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3224 | S->getRParenLoc()); |
| 3225 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3226 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3227 | template<typename Derived> |
| 3228 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3230 | // Transform the initialization statement |
| 3231 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3232 | if (Init.isInvalid()) |
| 3233 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3236 | OwningExprResult Cond(SemaRef); |
| 3237 | VarDecl *ConditionVar = 0; |
| 3238 | if (S->getConditionVariable()) { |
| 3239 | ConditionVar |
| 3240 | = cast_or_null<VarDecl>( |
| 3241 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3242 | if (!ConditionVar) |
| 3243 | return SemaRef.StmtError(); |
| 3244 | } else { |
| 3245 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3246 | |
| 3247 | if (Cond.isInvalid()) |
| 3248 | return SemaRef.StmtError(); |
| 3249 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3251 | // Transform the increment |
| 3252 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3253 | if (Inc.isInvalid()) |
| 3254 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | // Transform the body |
| 3257 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3258 | if (Body.isInvalid()) |
| 3259 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3261 | if (!getDerived().AlwaysRebuild() && |
| 3262 | Init.get() == S->getInit() && |
| 3263 | Cond.get() == S->getCond() && |
| 3264 | Inc.get() == S->getInc() && |
| 3265 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3266 | return SemaRef.Owned(S->Retain()); |
| 3267 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3268 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3269 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3270 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3271 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3272 | S->getRParenLoc(), move(Body)); |
| 3273 | } |
| 3274 | |
| 3275 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3276 | Sema::OwningStmtResult |
| 3277 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3280 | S->getLabel()); |
| 3281 | } |
| 3282 | |
| 3283 | template<typename Derived> |
| 3284 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3286 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3287 | if (Target.isInvalid()) |
| 3288 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3289 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3290 | if (!getDerived().AlwaysRebuild() && |
| 3291 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3292 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3293 | |
| 3294 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3295 | move(Target)); |
| 3296 | } |
| 3297 | |
| 3298 | template<typename Derived> |
| 3299 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3301 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | template<typename Derived> |
| 3305 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3306 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3307 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3308 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | template<typename Derived> |
| 3311 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3312 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3314 | if (Result.isInvalid()) |
| 3315 | return SemaRef.StmtError(); |
| 3316 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3318 | // to tell whether the return type of the function has changed. |
| 3319 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3320 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3322 | template<typename Derived> |
| 3323 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3325 | bool DeclChanged = false; |
| 3326 | llvm::SmallVector<Decl *, 4> Decls; |
| 3327 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3328 | D != DEnd; ++D) { |
| 3329 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3330 | if (!Transformed) |
| 3331 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3333 | if (Transformed != *D) |
| 3334 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3335 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3336 | Decls.push_back(Transformed); |
| 3337 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | return SemaRef.Owned(S->Retain()); |
| 3341 | |
| 3342 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | S->getStartLoc(), S->getEndLoc()); |
| 3344 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | template<typename Derived> |
| 3347 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | template<typename Derived> |
| 3354 | Sema::OwningStmtResult |
| 3355 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3356 | |
| 3357 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3358 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3359 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3360 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3361 | OwningExprResult AsmString(SemaRef); |
| 3362 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3363 | |
| 3364 | bool ExprsChanged = false; |
| 3365 | |
| 3366 | // Go through the outputs. |
| 3367 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3368 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3369 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3370 | // No need to transform the constraint literal. |
| 3371 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3372 | |
| 3373 | // Transform the output expr. |
| 3374 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3375 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3376 | if (Result.isInvalid()) |
| 3377 | return SemaRef.StmtError(); |
| 3378 | |
| 3379 | ExprsChanged |= Result.get() != OutputExpr; |
| 3380 | |
| 3381 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3382 | } |
| 3383 | |
| 3384 | // Go through the inputs. |
| 3385 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3386 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3387 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3388 | // No need to transform the constraint literal. |
| 3389 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3390 | |
| 3391 | // Transform the input expr. |
| 3392 | Expr *InputExpr = S->getInputExpr(I); |
| 3393 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3394 | if (Result.isInvalid()) |
| 3395 | return SemaRef.StmtError(); |
| 3396 | |
| 3397 | ExprsChanged |= Result.get() != InputExpr; |
| 3398 | |
| 3399 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3400 | } |
| 3401 | |
| 3402 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3403 | return SemaRef.Owned(S->Retain()); |
| 3404 | |
| 3405 | // Go through the clobbers. |
| 3406 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3407 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3408 | |
| 3409 | // No need to transform the asm string literal. |
| 3410 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3411 | |
| 3412 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3413 | S->isSimple(), |
| 3414 | S->isVolatile(), |
| 3415 | S->getNumOutputs(), |
| 3416 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3417 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3418 | move_arg(Constraints), |
| 3419 | move_arg(Exprs), |
| 3420 | move(AsmString), |
| 3421 | move_arg(Clobbers), |
| 3422 | S->getRParenLoc(), |
| 3423 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | |
| 3427 | template<typename Derived> |
| 3428 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3429 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3430 | // FIXME: Implement this |
| 3431 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3434 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3435 | template<typename Derived> |
| 3436 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | // FIXME: Implement this |
| 3439 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3440 | return SemaRef.Owned(S->Retain()); |
| 3441 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3443 | template<typename Derived> |
| 3444 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3446 | // FIXME: Implement this |
| 3447 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3449 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3451 | template<typename Derived> |
| 3452 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3453 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3454 | // FIXME: Implement this |
| 3455 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3457 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3459 | template<typename Derived> |
| 3460 | Sema::OwningStmtResult |
| 3461 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3463 | // FIXME: Implement this |
| 3464 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3465 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | template<typename Derived> |
| 3469 | Sema::OwningStmtResult |
| 3470 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3471 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3472 | // FIXME: Implement this |
| 3473 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | |
| 3478 | template<typename Derived> |
| 3479 | Sema::OwningStmtResult |
| 3480 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3481 | // Transform the exception declaration, if any. |
| 3482 | VarDecl *Var = 0; |
| 3483 | if (S->getExceptionDecl()) { |
| 3484 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3485 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3486 | ExceptionDecl->getDeclName()); |
| 3487 | |
| 3488 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3489 | if (T.isNull()) |
| 3490 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3491 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3492 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3493 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3494 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3495 | ExceptionDecl->getIdentifier(), |
| 3496 | ExceptionDecl->getLocation(), |
| 3497 | /*FIXME: Inaccurate*/ |
| 3498 | SourceRange(ExceptionDecl->getLocation())); |
| 3499 | if (!Var || Var->isInvalidDecl()) { |
| 3500 | if (Var) |
| 3501 | Var->Destroy(SemaRef.Context); |
| 3502 | return SemaRef.StmtError(); |
| 3503 | } |
| 3504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3506 | // Transform the actual exception handler. |
| 3507 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3508 | if (Handler.isInvalid()) { |
| 3509 | if (Var) |
| 3510 | Var->Destroy(SemaRef.Context); |
| 3511 | return SemaRef.StmtError(); |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 3515 | !Var && |
| 3516 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3518 | |
| 3519 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3520 | Var, |
| 3521 | move(Handler)); |
| 3522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | template<typename Derived> |
| 3525 | Sema::OwningStmtResult |
| 3526 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3527 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3529 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3530 | if (TryBlock.isInvalid()) |
| 3531 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3533 | // Transform the handlers. |
| 3534 | bool HandlerChanged = false; |
| 3535 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3536 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3538 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3539 | if (Handler.isInvalid()) |
| 3540 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3543 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3546 | if (!getDerived().AlwaysRebuild() && |
| 3547 | TryBlock.get() == S->getTryBlock() && |
| 3548 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3550 | |
| 3551 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3554 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3555 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3556 | // Expression transformation |
| 3557 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | template<typename Derived> |
| 3559 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3560 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3562 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | |
| 3564 | template<typename Derived> |
| 3565 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3566 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3567 | NestedNameSpecifier *Qualifier = 0; |
| 3568 | if (E->getQualifier()) { |
| 3569 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3570 | E->getQualifierRange()); |
| 3571 | if (!Qualifier) |
| 3572 | return SemaRef.ExprError(); |
| 3573 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3574 | |
| 3575 | ValueDecl *ND |
| 3576 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3577 | if (!ND) |
| 3578 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3580 | if (!getDerived().AlwaysRebuild() && |
| 3581 | Qualifier == E->getQualifier() && |
| 3582 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3583 | !E->hasExplicitTemplateArgumentList()) { |
| 3584 | |
| 3585 | // Mark it referenced in the new context regardless. |
| 3586 | // FIXME: this is a bit instantiation-specific. |
| 3587 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3588 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3589 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3590 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3591 | |
| 3592 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3593 | if (E->hasExplicitTemplateArgumentList()) { |
| 3594 | TemplateArgs = &TransArgs; |
| 3595 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3596 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3597 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3598 | TemplateArgumentLoc Loc; |
| 3599 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3600 | return SemaRef.ExprError(); |
| 3601 | TransArgs.addArgument(Loc); |
| 3602 | } |
| 3603 | } |
| 3604 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3605 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3606 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3609 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3611 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3613 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3615 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3617 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3621 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3623 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3624 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3625 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3627 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3629 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3630 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3633 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3634 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3635 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3636 | return SemaRef.Owned(E->Retain()); |
| 3637 | } |
| 3638 | |
| 3639 | template<typename Derived> |
| 3640 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3641 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3642 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3643 | if (SubExpr.isInvalid()) |
| 3644 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | return SemaRef.Owned(E->Retain()); |
| 3648 | |
| 3649 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3650 | E->getRParen()); |
| 3651 | } |
| 3652 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | template<typename Derived> |
| 3654 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3655 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3656 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3657 | if (SubExpr.isInvalid()) |
| 3658 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3660 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | return SemaRef.Owned(E->Retain()); |
| 3662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3663 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3664 | E->getOpcode(), |
| 3665 | move(SubExpr)); |
| 3666 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3668 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3670 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3671 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3672 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3673 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3674 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3675 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3676 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3678 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3679 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3681 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3683 | E->getSourceRange()); |
| 3684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3686 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3687 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3688 | // C++0x [expr.sizeof]p1: |
| 3689 | // The operand is either an expression, which is an unevaluated operand |
| 3690 | // [...] |
| 3691 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3693 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3694 | if (SubExpr.isInvalid()) |
| 3695 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3696 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3697 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3698 | return SemaRef.Owned(E->Retain()); |
| 3699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3700 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3701 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3702 | E->isSizeOf(), |
| 3703 | E->getSourceRange()); |
| 3704 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3706 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3707 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3708 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3709 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3710 | if (LHS.isInvalid()) |
| 3711 | return SemaRef.ExprError(); |
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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3714 | if (RHS.isInvalid()) |
| 3715 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3716 | |
| 3717 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3718 | if (!getDerived().AlwaysRebuild() && |
| 3719 | LHS.get() == E->getLHS() && |
| 3720 | RHS.get() == E->getRHS()) |
| 3721 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3722 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3723 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3724 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3725 | move(RHS), |
| 3726 | E->getRBracketLoc()); |
| 3727 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3728 | |
| 3729 | template<typename Derived> |
| 3730 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3731 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3732 | // Transform the callee. |
| 3733 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3734 | if (Callee.isInvalid()) |
| 3735 | return SemaRef.ExprError(); |
| 3736 | |
| 3737 | // Transform arguments. |
| 3738 | bool ArgChanged = false; |
| 3739 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3740 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3741 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3742 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3743 | if (Arg.isInvalid()) |
| 3744 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | // FIXME: Wrong source location information for the ','. |
| 3747 | FakeCommaLocs.push_back( |
| 3748 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | |
| 3750 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | Args.push_back(Arg.takeAs<Expr>()); |
| 3752 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | if (!getDerived().AlwaysRebuild() && |
| 3755 | Callee.get() == E->getCallee() && |
| 3756 | !ArgChanged) |
| 3757 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3758 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3759 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3761 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3762 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3763 | move_arg(Args), |
| 3764 | FakeCommaLocs.data(), |
| 3765 | E->getRParenLoc()); |
| 3766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3767 | |
| 3768 | template<typename Derived> |
| 3769 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3770 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3772 | if (Base.isInvalid()) |
| 3773 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3774 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3775 | NestedNameSpecifier *Qualifier = 0; |
| 3776 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3778 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3779 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3780 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3781 | return SemaRef.ExprError(); |
| 3782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3784 | ValueDecl *Member |
| 3785 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3786 | if (!Member) |
| 3787 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3789 | if (!getDerived().AlwaysRebuild() && |
| 3790 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3791 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3792 | Member == E->getMemberDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3793 | !E->hasExplicitTemplateArgumentList()) { |
| 3794 | |
| 3795 | // Mark it referenced in the new context regardless. |
| 3796 | // FIXME: this is a bit instantiation-specific. |
| 3797 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3799 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3800 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3801 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3802 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3803 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3804 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3805 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3806 | TemplateArgumentLoc Loc; |
| 3807 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3808 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3809 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3810 | } |
| 3811 | } |
| 3812 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3813 | // FIXME: Bogus source location for the operator |
| 3814 | SourceLocation FakeOperatorLoc |
| 3815 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3816 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3817 | // FIXME: to do this check properly, we will need to preserve the |
| 3818 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3819 | // base (and therefore couldn't do the check) and a |
| 3820 | // nested-name-qualifier (and therefore could do the lookup). |
| 3821 | NamedDecl *FirstQualifierInScope = 0; |
| 3822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3823 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3824 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3825 | Qualifier, |
| 3826 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3827 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3828 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3829 | (E->hasExplicitTemplateArgumentList() |
| 3830 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3831 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3832 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3835 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3836 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3838 | if (LHS.isInvalid()) |
| 3839 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3841 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3842 | if (RHS.isInvalid()) |
| 3843 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | if (!getDerived().AlwaysRebuild() && |
| 3846 | LHS.get() == E->getLHS() && |
| 3847 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | return SemaRef.Owned(E->Retain()); |
| 3849 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3850 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3851 | move(LHS), move(RHS)); |
| 3852 | } |
| 3853 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3854 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3855 | Sema::OwningExprResult |
| 3856 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3857 | CompoundAssignOperator *E) { |
| 3858 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3861 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3862 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3863 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3865 | if (Cond.isInvalid()) |
| 3866 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3869 | if (LHS.isInvalid()) |
| 3870 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3872 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3873 | if (RHS.isInvalid()) |
| 3874 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3876 | if (!getDerived().AlwaysRebuild() && |
| 3877 | Cond.get() == E->getCond() && |
| 3878 | LHS.get() == E->getLHS() && |
| 3879 | RHS.get() == E->getRHS()) |
| 3880 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | |
| 3882 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3883 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3885 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3886 | move(RHS)); |
| 3887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | |
| 3889 | template<typename Derived> |
| 3890 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3891 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3892 | // Implicit casts are eliminated during transformation, since they |
| 3893 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3894 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3897 | template<typename Derived> |
| 3898 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3899 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3900 | TypeSourceInfo *OldT; |
| 3901 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | { |
| 3903 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3904 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3905 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3906 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3908 | OldT = E->getTypeInfoAsWritten(); |
| 3909 | NewT = getDerived().TransformType(OldT); |
| 3910 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3911 | return SemaRef.ExprError(); |
| 3912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3913 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3914 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3915 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | if (SubExpr.isInvalid()) |
| 3917 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3919 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3920 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | return SemaRef.Owned(E->Retain()); |
| 3923 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3924 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3925 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3926 | E->getRParenLoc(), |
| 3927 | move(SubExpr)); |
| 3928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3929 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3931 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3932 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3933 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3934 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3935 | if (!NewT) |
| 3936 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3938 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3939 | if (Init.isInvalid()) |
| 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 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3943 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3946 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3947 | // Note: the expression type doesn't necessarily match the |
| 3948 | // type-as-written, but that's okay, because it should always be |
| 3949 | // derivable from the initializer. |
| 3950 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3951 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3953 | move(Init)); |
| 3954 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | template<typename Derived> |
| 3957 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3958 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3960 | if (Base.isInvalid()) |
| 3961 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3962 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | if (!getDerived().AlwaysRebuild() && |
| 3964 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | return SemaRef.Owned(E->Retain()); |
| 3966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3967 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3969 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3970 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3971 | E->getAccessorLoc(), |
| 3972 | E->getAccessor()); |
| 3973 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3977 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3978 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3981 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3982 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3983 | if (Init.isInvalid()) |
| 3984 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3985 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3986 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3987 | Inits.push_back(Init.takeAs<Expr>()); |
| 3988 | } |
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 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | return SemaRef.Owned(E->Retain()); |
| 3992 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3994 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3996 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3997 | template<typename Derived> |
| 3998 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3999 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4000 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4002 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4004 | if (Init.isInvalid()) |
| 4005 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4006 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4007 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4008 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4009 | bool ExprChanged = false; |
| 4010 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4011 | DEnd = E->designators_end(); |
| 4012 | D != DEnd; ++D) { |
| 4013 | if (D->isFieldDesignator()) { |
| 4014 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4015 | D->getDotLoc(), |
| 4016 | D->getFieldLoc())); |
| 4017 | continue; |
| 4018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4020 | if (D->isArrayDesignator()) { |
| 4021 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4022 | if (Index.isInvalid()) |
| 4023 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4024 | |
| 4025 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4026 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4029 | ArrayExprs.push_back(Index.release()); |
| 4030 | continue; |
| 4031 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4034 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4035 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4036 | if (Start.isInvalid()) |
| 4037 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4038 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4039 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4040 | if (End.isInvalid()) |
| 4041 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4042 | |
| 4043 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4044 | End.get(), |
| 4045 | D->getLBracketLoc(), |
| 4046 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4049 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | ArrayExprs.push_back(Start.release()); |
| 4052 | ArrayExprs.push_back(End.release()); |
| 4053 | } |
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 | if (!getDerived().AlwaysRebuild() && |
| 4056 | Init.get() == E->getInit() && |
| 4057 | !ExprChanged) |
| 4058 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4060 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4061 | E->getEqualOrColonLoc(), |
| 4062 | E->usesGNUSyntax(), move(Init)); |
| 4063 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4064 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4065 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4067 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4068 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4069 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4070 | |
| 4071 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4072 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4073 | QualType T = getDerived().TransformType(E->getType()); |
| 4074 | if (T.isNull()) |
| 4075 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | if (!getDerived().AlwaysRebuild() && |
| 4078 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4079 | return SemaRef.Owned(E->Retain()); |
| 4080 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4081 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4082 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4086 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4087 | // FIXME: Do we want the type as written? |
| 4088 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4090 | { |
| 4091 | // FIXME: Source location isn't quite accurate. |
| 4092 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4093 | T = getDerived().TransformType(E->getType()); |
| 4094 | if (T.isNull()) |
| 4095 | return SemaRef.ExprError(); |
| 4096 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4097 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4098 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4099 | if (SubExpr.isInvalid()) |
| 4100 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4103 | T == E->getType() && |
| 4104 | SubExpr.get() == E->getSubExpr()) |
| 4105 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4106 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4108 | T, E->getRParenLoc()); |
| 4109 | } |
| 4110 | |
| 4111 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4112 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4113 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | bool ArgumentChanged = false; |
| 4115 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4116 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4117 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4118 | if (Init.isInvalid()) |
| 4119 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4120 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4121 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4122 | Inits.push_back(Init.takeAs<Expr>()); |
| 4123 | } |
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 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4126 | move_arg(Inits), |
| 4127 | E->getRParenLoc()); |
| 4128 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | /// \brief Transform an address-of-label expression. |
| 4131 | /// |
| 4132 | /// By default, the transformation of an address-of-label expression always |
| 4133 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4134 | /// the corresponding label statement by semantic analysis. |
| 4135 | template<typename Derived> |
| 4136 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4137 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4138 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4139 | E->getLabel()); |
| 4140 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4141 | |
| 4142 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4143 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4144 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4146 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4147 | if (SubStmt.isInvalid()) |
| 4148 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | if (!getDerived().AlwaysRebuild() && |
| 4151 | SubStmt.get() == E->getSubStmt()) |
| 4152 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
| 4154 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | move(SubStmt), |
| 4156 | E->getRParenLoc()); |
| 4157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | template<typename Derived> |
| 4160 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4161 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4162 | QualType T1, T2; |
| 4163 | { |
| 4164 | // FIXME: Source location isn't quite accurate. |
| 4165 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4166 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4167 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4168 | if (T1.isNull()) |
| 4169 | return SemaRef.ExprError(); |
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 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4172 | if (T2.isNull()) |
| 4173 | return SemaRef.ExprError(); |
| 4174 | } |
| 4175 | |
| 4176 | if (!getDerived().AlwaysRebuild() && |
| 4177 | T1 == E->getArgType1() && |
| 4178 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | return SemaRef.Owned(E->Retain()); |
| 4180 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4182 | T1, T2, E->getRParenLoc()); |
| 4183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | template<typename Derived> |
| 4186 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4187 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4189 | if (Cond.isInvalid()) |
| 4190 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4193 | if (LHS.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 RHS = getDerived().TransformExpr(E->getRHS()); |
| 4197 | if (RHS.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 | if (!getDerived().AlwaysRebuild() && |
| 4201 | Cond.get() == E->getCond() && |
| 4202 | LHS.get() == E->getLHS() && |
| 4203 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4204 | return SemaRef.Owned(E->Retain()); |
| 4205 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4206 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4207 | move(Cond), move(LHS), move(RHS), |
| 4208 | E->getRParenLoc()); |
| 4209 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4210 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4213 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | template<typename Derived> |
| 4218 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4219 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4220 | switch (E->getOperator()) { |
| 4221 | case OO_New: |
| 4222 | case OO_Delete: |
| 4223 | case OO_Array_New: |
| 4224 | case OO_Array_Delete: |
| 4225 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4226 | return SemaRef.ExprError(); |
| 4227 | |
| 4228 | case OO_Call: { |
| 4229 | // This is a call to an object's operator(). |
| 4230 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4231 | |
| 4232 | // Transform the object itself. |
| 4233 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4234 | if (Object.isInvalid()) |
| 4235 | return SemaRef.ExprError(); |
| 4236 | |
| 4237 | // FIXME: Poor location information |
| 4238 | SourceLocation FakeLParenLoc |
| 4239 | = SemaRef.PP.getLocForEndOfToken( |
| 4240 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4241 | |
| 4242 | // Transform the call arguments. |
| 4243 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4244 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4245 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4246 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4247 | break; |
| 4248 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4249 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4250 | if (Arg.isInvalid()) |
| 4251 | return SemaRef.ExprError(); |
| 4252 | |
| 4253 | // FIXME: Poor source location information. |
| 4254 | SourceLocation FakeCommaLoc |
| 4255 | = SemaRef.PP.getLocForEndOfToken( |
| 4256 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4257 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4258 | Args.push_back(Arg.release()); |
| 4259 | } |
| 4260 | |
| 4261 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4262 | move_arg(Args), |
| 4263 | FakeCommaLocs.data(), |
| 4264 | E->getLocEnd()); |
| 4265 | } |
| 4266 | |
| 4267 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4268 | case OO_##Name: |
| 4269 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4270 | #include "clang/Basic/OperatorKinds.def" |
| 4271 | case OO_Subscript: |
| 4272 | // Handled below. |
| 4273 | break; |
| 4274 | |
| 4275 | case OO_Conditional: |
| 4276 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4277 | return SemaRef.ExprError(); |
| 4278 | |
| 4279 | case OO_None: |
| 4280 | case NUM_OVERLOADED_OPERATORS: |
| 4281 | llvm_unreachable("not an overloaded operator?"); |
| 4282 | return SemaRef.ExprError(); |
| 4283 | } |
| 4284 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4286 | if (Callee.isInvalid()) |
| 4287 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4289 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4290 | if (First.isInvalid()) |
| 4291 | return SemaRef.ExprError(); |
| 4292 | |
| 4293 | OwningExprResult Second(SemaRef); |
| 4294 | if (E->getNumArgs() == 2) { |
| 4295 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4296 | if (Second.isInvalid()) |
| 4297 | return SemaRef.ExprError(); |
| 4298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4299 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4300 | if (!getDerived().AlwaysRebuild() && |
| 4301 | Callee.get() == E->getCallee() && |
| 4302 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4304 | return SemaRef.Owned(E->Retain()); |
| 4305 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4307 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4308 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4309 | move(First), |
| 4310 | move(Second)); |
| 4311 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | template<typename Derived> |
| 4314 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4315 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4316 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4317 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4320 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4321 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4322 | TypeSourceInfo *OldT; |
| 4323 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4324 | { |
| 4325 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4326 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4327 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4328 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4330 | OldT = E->getTypeInfoAsWritten(); |
| 4331 | NewT = getDerived().TransformType(OldT); |
| 4332 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4333 | return SemaRef.ExprError(); |
| 4334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4336 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4337 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4338 | if (SubExpr.isInvalid()) |
| 4339 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4341 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4342 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | return SemaRef.Owned(E->Retain()); |
| 4345 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4346 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4349 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4350 | SourceLocation FakeRParenLoc |
| 4351 | = SemaRef.PP.getLocForEndOfToken( |
| 4352 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4353 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4355 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4356 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4357 | FakeRAngleLoc, |
| 4358 | FakeRAngleLoc, |
| 4359 | move(SubExpr), |
| 4360 | FakeRParenLoc); |
| 4361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4362 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4363 | template<typename Derived> |
| 4364 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4365 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4366 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4368 | |
| 4369 | template<typename Derived> |
| 4370 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4371 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4372 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | } |
| 4374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | template<typename Derived> |
| 4376 | Sema::OwningExprResult |
| 4377 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4378 | CXXReinterpretCastExpr *E) { |
| 4379 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4381 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | template<typename Derived> |
| 4383 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4384 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4385 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | template<typename Derived> |
| 4389 | Sema::OwningExprResult |
| 4390 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4391 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4392 | TypeSourceInfo *OldT; |
| 4393 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | { |
| 4395 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4397 | OldT = E->getTypeInfoAsWritten(); |
| 4398 | NewT = getDerived().TransformType(OldT); |
| 4399 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | return SemaRef.ExprError(); |
| 4401 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4403 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4404 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4405 | if (SubExpr.isInvalid()) |
| 4406 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4409 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | return SemaRef.Owned(E->Retain()); |
| 4412 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | // FIXME: The end of the type's source range is wrong |
| 4414 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4415 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4416 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4418 | move(SubExpr), |
| 4419 | E->getRParenLoc()); |
| 4420 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4421 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4422 | template<typename Derived> |
| 4423 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4424 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | if (E->isTypeOperand()) { |
| 4426 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4427 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4428 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4429 | if (T.isNull()) |
| 4430 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4433 | T == E->getTypeOperand()) |
| 4434 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4437 | /*FIXME:*/E->getLocStart(), |
| 4438 | T, |
| 4439 | E->getLocEnd()); |
| 4440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4442 | // We don't know whether the expression is potentially evaluated until |
| 4443 | // after we perform semantic analysis, so the expression is potentially |
| 4444 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4449 | if (SubExpr.isInvalid()) |
| 4450 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4453 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4454 | return SemaRef.Owned(E->Retain()); |
| 4455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4457 | /*FIXME:*/E->getLocStart(), |
| 4458 | move(SubExpr), |
| 4459 | E->getLocEnd()); |
| 4460 | } |
| 4461 | |
| 4462 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4463 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4464 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | template<typename Derived> |
| 4469 | Sema::OwningExprResult |
| 4470 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4471 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4472 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4473 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | template<typename Derived> |
| 4476 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4477 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4478 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | QualType T = getDerived().TransformType(E->getType()); |
| 4481 | if (T.isNull()) |
| 4482 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4485 | T == E->getType()) |
| 4486 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4487 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4488 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | template<typename Derived> |
| 4492 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4493 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4494 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4495 | if (SubExpr.isInvalid()) |
| 4496 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4497 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | if (!getDerived().AlwaysRebuild() && |
| 4499 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | |
| 4502 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4503 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4505 | template<typename Derived> |
| 4506 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4507 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4510 | if (!Param) |
| 4511 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame^] | 4513 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | Param == E->getParam()) |
| 4515 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4516 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4517 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | template<typename Derived> |
| 4521 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4522 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4523 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4524 | |
| 4525 | QualType T = getDerived().TransformType(E->getType()); |
| 4526 | if (T.isNull()) |
| 4527 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4528 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | if (!getDerived().AlwaysRebuild() && |
| 4530 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4531 | return SemaRef.Owned(E->Retain()); |
| 4532 | |
| 4533 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4535 | T, |
| 4536 | E->getRParenLoc()); |
| 4537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4539 | template<typename Derived> |
| 4540 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4541 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4542 | // Transform the type that we're allocating |
| 4543 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4544 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4545 | if (AllocType.isNull()) |
| 4546 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4548 | // Transform the size of the array we're allocating (if any). |
| 4549 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4550 | if (ArraySize.isInvalid()) |
| 4551 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | // Transform the placement arguments (if any). |
| 4554 | bool ArgumentChanged = false; |
| 4555 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4556 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4557 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4558 | if (Arg.isInvalid()) |
| 4559 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4562 | PlacementArgs.push_back(Arg.take()); |
| 4563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4565 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4566 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4567 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4568 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4569 | if (Arg.isInvalid()) |
| 4570 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4573 | ConstructorArgs.push_back(Arg.take()); |
| 4574 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4576 | if (!getDerived().AlwaysRebuild() && |
| 4577 | AllocType == E->getAllocatedType() && |
| 4578 | ArraySize.get() == E->getArraySize() && |
| 4579 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | return SemaRef.Owned(E->Retain()); |
| 4581 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4582 | if (!ArraySize.get()) { |
| 4583 | // If no array size was specified, but the new expression was |
| 4584 | // instantiated with an array type (e.g., "new T" where T is |
| 4585 | // instantiated with "int[4]"), extract the outer bound from the |
| 4586 | // array type as our array size. We do this with constant and |
| 4587 | // dependently-sized array types. |
| 4588 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4589 | if (!ArrayT) { |
| 4590 | // Do nothing |
| 4591 | } else if (const ConstantArrayType *ConsArrayT |
| 4592 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4593 | ArraySize |
| 4594 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4595 | ConsArrayT->getSize(), |
| 4596 | SemaRef.Context.getSizeType(), |
| 4597 | /*FIXME:*/E->getLocStart())); |
| 4598 | AllocType = ConsArrayT->getElementType(); |
| 4599 | } else if (const DependentSizedArrayType *DepArrayT |
| 4600 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4601 | if (DepArrayT->getSizeExpr()) { |
| 4602 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4603 | AllocType = DepArrayT->getElementType(); |
| 4604 | } |
| 4605 | } |
| 4606 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4607 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4608 | E->isGlobalNew(), |
| 4609 | /*FIXME:*/E->getLocStart(), |
| 4610 | move_arg(PlacementArgs), |
| 4611 | /*FIXME:*/E->getLocStart(), |
| 4612 | E->isParenTypeId(), |
| 4613 | AllocType, |
| 4614 | /*FIXME:*/E->getLocStart(), |
| 4615 | /*FIXME:*/SourceRange(), |
| 4616 | move(ArraySize), |
| 4617 | /*FIXME:*/E->getLocStart(), |
| 4618 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4619 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4620 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4622 | template<typename Derived> |
| 4623 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4624 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4626 | if (Operand.isInvalid()) |
| 4627 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4628 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4629 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4630 | Operand.get() == E->getArgument()) |
| 4631 | return SemaRef.Owned(E->Retain()); |
| 4632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4634 | E->isGlobalDelete(), |
| 4635 | E->isArrayForm(), |
| 4636 | move(Operand)); |
| 4637 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4638 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | template<typename Derived> |
| 4640 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4641 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4642 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4643 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4644 | if (Base.isInvalid()) |
| 4645 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4646 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4647 | NestedNameSpecifier *Qualifier |
| 4648 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4649 | E->getQualifierRange()); |
| 4650 | if (E->getQualifier() && !Qualifier) |
| 4651 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4652 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4653 | QualType DestroyedType; |
| 4654 | { |
| 4655 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4656 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4657 | if (DestroyedType.isNull()) |
| 4658 | return SemaRef.ExprError(); |
| 4659 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4660 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4661 | if (!getDerived().AlwaysRebuild() && |
| 4662 | Base.get() == E->getBase() && |
| 4663 | Qualifier == E->getQualifier() && |
| 4664 | DestroyedType == E->getDestroyedType()) |
| 4665 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4666 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4667 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4668 | E->getOperatorLoc(), |
| 4669 | E->isArrow(), |
| 4670 | E->getDestroyedTypeLoc(), |
| 4671 | DestroyedType, |
| 4672 | Qualifier, |
| 4673 | E->getQualifierRange()); |
| 4674 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4676 | template<typename Derived> |
| 4677 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4678 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4679 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4680 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4681 | |
| 4682 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4683 | Sema::LookupOrdinaryName); |
| 4684 | |
| 4685 | // Transform all the decls. |
| 4686 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4687 | E = Old->decls_end(); I != E; ++I) { |
| 4688 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4689 | if (!InstD) { |
| 4690 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4691 | // This can happen because of dependent hiding. |
| 4692 | if (isa<UsingShadowDecl>(*I)) |
| 4693 | continue; |
| 4694 | else |
| 4695 | return SemaRef.ExprError(); |
| 4696 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4697 | |
| 4698 | // Expand using declarations. |
| 4699 | if (isa<UsingDecl>(InstD)) { |
| 4700 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4701 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4702 | E = UD->shadow_end(); I != E; ++I) |
| 4703 | R.addDecl(*I); |
| 4704 | continue; |
| 4705 | } |
| 4706 | |
| 4707 | R.addDecl(InstD); |
| 4708 | } |
| 4709 | |
| 4710 | // Resolve a kind, but don't do any further analysis. If it's |
| 4711 | // ambiguous, the callee needs to deal with it. |
| 4712 | R.resolveKind(); |
| 4713 | |
| 4714 | // Rebuild the nested-name qualifier, if present. |
| 4715 | CXXScopeSpec SS; |
| 4716 | NestedNameSpecifier *Qualifier = 0; |
| 4717 | if (Old->getQualifier()) { |
| 4718 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4719 | Old->getQualifierRange()); |
| 4720 | if (!Qualifier) |
| 4721 | return SemaRef.ExprError(); |
| 4722 | |
| 4723 | SS.setScopeRep(Qualifier); |
| 4724 | SS.setRange(Old->getQualifierRange()); |
| 4725 | } |
| 4726 | |
| 4727 | // If we have no template arguments, it's a normal declaration name. |
| 4728 | if (!Old->hasExplicitTemplateArgs()) |
| 4729 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4730 | |
| 4731 | // If we have template arguments, rebuild them, then rebuild the |
| 4732 | // templateid expression. |
| 4733 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4734 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4735 | TemplateArgumentLoc Loc; |
| 4736 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4737 | return SemaRef.ExprError(); |
| 4738 | TransArgs.addArgument(Loc); |
| 4739 | } |
| 4740 | |
| 4741 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4742 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4745 | template<typename Derived> |
| 4746 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4747 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4751 | if (T.isNull()) |
| 4752 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4755 | T == E->getQueriedType()) |
| 4756 | return SemaRef.Owned(E->Retain()); |
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 | // FIXME: Bad location information |
| 4759 | SourceLocation FakeLParenLoc |
| 4760 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4761 | |
| 4762 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4763 | E->getLocStart(), |
| 4764 | /*FIXME:*/FakeLParenLoc, |
| 4765 | T, |
| 4766 | E->getLocEnd()); |
| 4767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4768 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4769 | template<typename Derived> |
| 4770 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4771 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4772 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4774 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4775 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | if (!NNS) |
| 4777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4778 | |
| 4779 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4780 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4781 | if (!Name) |
| 4782 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4783 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4784 | if (!E->hasExplicitTemplateArgs()) { |
| 4785 | if (!getDerived().AlwaysRebuild() && |
| 4786 | NNS == E->getQualifier() && |
| 4787 | Name == E->getDeclName()) |
| 4788 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4790 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4791 | E->getQualifierRange(), |
| 4792 | Name, E->getLocation(), |
| 4793 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4794 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4795 | |
| 4796 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4797 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4798 | TemplateArgumentLoc Loc; |
| 4799 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4801 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4804 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4805 | E->getQualifierRange(), |
| 4806 | Name, E->getLocation(), |
| 4807 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | template<typename Derived> |
| 4811 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4812 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4813 | // CXXConstructExprs are always implicit, so when we have a |
| 4814 | // 1-argument construction we just transform that argument. |
| 4815 | if (E->getNumArgs() == 1 || |
| 4816 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 4817 | return getDerived().TransformExpr(E->getArg(0)); |
| 4818 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4819 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4820 | |
| 4821 | QualType T = getDerived().TransformType(E->getType()); |
| 4822 | if (T.isNull()) |
| 4823 | return SemaRef.ExprError(); |
| 4824 | |
| 4825 | CXXConstructorDecl *Constructor |
| 4826 | = cast_or_null<CXXConstructorDecl>( |
| 4827 | getDerived().TransformDecl(E->getConstructor())); |
| 4828 | if (!Constructor) |
| 4829 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4830 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4831 | bool ArgumentChanged = false; |
| 4832 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | ArgEnd = E->arg_end(); |
| 4835 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4836 | if (getDerived().DropCallArgument(*Arg)) { |
| 4837 | ArgumentChanged = true; |
| 4838 | break; |
| 4839 | } |
| 4840 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4841 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4842 | if (TransArg.isInvalid()) |
| 4843 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4845 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4846 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4847 | } |
| 4848 | |
| 4849 | if (!getDerived().AlwaysRebuild() && |
| 4850 | T == E->getType() && |
| 4851 | Constructor == E->getConstructor() && |
| 4852 | !ArgumentChanged) |
| 4853 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4855 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4856 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4857 | move_arg(Args)); |
| 4858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4859 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4860 | /// \brief Transform a C++ temporary-binding expression. |
| 4861 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4862 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4863 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4864 | template<typename Derived> |
| 4865 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4866 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4867 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4868 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4869 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 4870 | /// \brief Transform a C++ reference-binding expression. |
| 4871 | /// |
| 4872 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 4873 | /// transform the subexpression and return that. |
| 4874 | template<typename Derived> |
| 4875 | Sema::OwningExprResult |
| 4876 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 4877 | return getDerived().TransformExpr(E->getSubExpr()); |
| 4878 | } |
| 4879 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4880 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4881 | /// be destroyed after the expression is evaluated. |
| 4882 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4883 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4884 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4885 | template<typename Derived> |
| 4886 | Sema::OwningExprResult |
| 4887 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4888 | CXXExprWithTemporaries *E) { |
| 4889 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4890 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4892 | template<typename Derived> |
| 4893 | Sema::OwningExprResult |
| 4894 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4895 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4897 | QualType T = getDerived().TransformType(E->getType()); |
| 4898 | if (T.isNull()) |
| 4899 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4901 | CXXConstructorDecl *Constructor |
| 4902 | = cast_or_null<CXXConstructorDecl>( |
| 4903 | getDerived().TransformDecl(E->getConstructor())); |
| 4904 | if (!Constructor) |
| 4905 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4906 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4907 | bool ArgumentChanged = false; |
| 4908 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4909 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4911 | ArgEnd = E->arg_end(); |
| 4912 | Arg != ArgEnd; ++Arg) { |
| 4913 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4914 | if (TransArg.isInvalid()) |
| 4915 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4917 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4918 | Args.push_back((Expr *)TransArg.release()); |
| 4919 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4921 | if (!getDerived().AlwaysRebuild() && |
| 4922 | T == E->getType() && |
| 4923 | Constructor == E->getConstructor() && |
| 4924 | !ArgumentChanged) |
| 4925 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4926 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4927 | // FIXME: Bogus location information |
| 4928 | SourceLocation CommaLoc; |
| 4929 | if (Args.size() > 1) { |
| 4930 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4931 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4932 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4933 | } |
| 4934 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4935 | T, |
| 4936 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4937 | move_arg(Args), |
| 4938 | &CommaLoc, |
| 4939 | E->getLocEnd()); |
| 4940 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4942 | template<typename Derived> |
| 4943 | Sema::OwningExprResult |
| 4944 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4945 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4946 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4947 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4948 | if (T.isNull()) |
| 4949 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4951 | bool ArgumentChanged = false; |
| 4952 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4953 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4954 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4955 | ArgEnd = E->arg_end(); |
| 4956 | Arg != ArgEnd; ++Arg) { |
| 4957 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4958 | if (TransArg.isInvalid()) |
| 4959 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4962 | FakeCommaLocs.push_back( |
| 4963 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4964 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4965 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4967 | if (!getDerived().AlwaysRebuild() && |
| 4968 | T == E->getTypeAsWritten() && |
| 4969 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4970 | return SemaRef.Owned(E->Retain()); |
| 4971 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4972 | // FIXME: we're faking the locations of the commas |
| 4973 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4974 | T, |
| 4975 | E->getLParenLoc(), |
| 4976 | move_arg(Args), |
| 4977 | FakeCommaLocs.data(), |
| 4978 | E->getRParenLoc()); |
| 4979 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4981 | template<typename Derived> |
| 4982 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4983 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4984 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4985 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4986 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4987 | Expr *OldBase; |
| 4988 | QualType BaseType; |
| 4989 | QualType ObjectType; |
| 4990 | if (!E->isImplicitAccess()) { |
| 4991 | OldBase = E->getBase(); |
| 4992 | Base = getDerived().TransformExpr(OldBase); |
| 4993 | if (Base.isInvalid()) |
| 4994 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4995 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4996 | // Start the member reference and compute the object's type. |
| 4997 | Sema::TypeTy *ObjectTy = 0; |
| 4998 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4999 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5000 | E->isArrow()? tok::arrow : tok::period, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5001 | ObjectTy); |
| 5002 | if (Base.isInvalid()) |
| 5003 | return SemaRef.ExprError(); |
| 5004 | |
| 5005 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5006 | BaseType = ((Expr*) Base.get())->getType(); |
| 5007 | } else { |
| 5008 | OldBase = 0; |
| 5009 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5010 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5011 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5012 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5013 | // Transform the first part of the nested-name-specifier that qualifies |
| 5014 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5015 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5016 | = getDerived().TransformFirstQualifierInScope( |
| 5017 | E->getFirstQualifierFoundInScope(), |
| 5018 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5020 | NestedNameSpecifier *Qualifier = 0; |
| 5021 | if (E->getQualifier()) { |
| 5022 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5023 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5024 | ObjectType, |
| 5025 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5026 | if (!Qualifier) |
| 5027 | return SemaRef.ExprError(); |
| 5028 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5029 | |
| 5030 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5031 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5032 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5033 | if (!Name) |
| 5034 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5036 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5037 | // This is a reference to a member without an explicitly-specified |
| 5038 | // template argument list. Optimize for this common case. |
| 5039 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5040 | Base.get() == OldBase && |
| 5041 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5042 | Qualifier == E->getQualifier() && |
| 5043 | Name == E->getMember() && |
| 5044 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5045 | return SemaRef.Owned(E->Retain()); |
| 5046 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5047 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5048 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5049 | E->isArrow(), |
| 5050 | E->getOperatorLoc(), |
| 5051 | Qualifier, |
| 5052 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5053 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5054 | Name, |
| 5055 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5056 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5057 | } |
| 5058 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5059 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5060 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5061 | TemplateArgumentLoc Loc; |
| 5062 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5063 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5064 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5067 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5068 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5069 | E->isArrow(), |
| 5070 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5071 | Qualifier, |
| 5072 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5073 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5074 | Name, |
| 5075 | E->getMemberLoc(), |
| 5076 | &TransArgs); |
| 5077 | } |
| 5078 | |
| 5079 | template<typename Derived> |
| 5080 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5081 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5082 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5083 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5084 | QualType BaseType; |
| 5085 | if (!Old->isImplicitAccess()) { |
| 5086 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5087 | if (Base.isInvalid()) |
| 5088 | return SemaRef.ExprError(); |
| 5089 | BaseType = ((Expr*) Base.get())->getType(); |
| 5090 | } else { |
| 5091 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5092 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5093 | |
| 5094 | NestedNameSpecifier *Qualifier = 0; |
| 5095 | if (Old->getQualifier()) { |
| 5096 | Qualifier |
| 5097 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 5098 | Old->getQualifierRange()); |
| 5099 | if (Qualifier == 0) |
| 5100 | return SemaRef.ExprError(); |
| 5101 | } |
| 5102 | |
| 5103 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5104 | Sema::LookupOrdinaryName); |
| 5105 | |
| 5106 | // Transform all the decls. |
| 5107 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5108 | E = Old->decls_end(); I != E; ++I) { |
| 5109 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5110 | if (!InstD) { |
| 5111 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5112 | // This can happen because of dependent hiding. |
| 5113 | if (isa<UsingShadowDecl>(*I)) |
| 5114 | continue; |
| 5115 | else |
| 5116 | return SemaRef.ExprError(); |
| 5117 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5118 | |
| 5119 | // Expand using declarations. |
| 5120 | if (isa<UsingDecl>(InstD)) { |
| 5121 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5122 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5123 | E = UD->shadow_end(); I != E; ++I) |
| 5124 | R.addDecl(*I); |
| 5125 | continue; |
| 5126 | } |
| 5127 | |
| 5128 | R.addDecl(InstD); |
| 5129 | } |
| 5130 | |
| 5131 | R.resolveKind(); |
| 5132 | |
| 5133 | TemplateArgumentListInfo TransArgs; |
| 5134 | if (Old->hasExplicitTemplateArgs()) { |
| 5135 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5136 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5137 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5138 | TemplateArgumentLoc Loc; |
| 5139 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5140 | Loc)) |
| 5141 | return SemaRef.ExprError(); |
| 5142 | TransArgs.addArgument(Loc); |
| 5143 | } |
| 5144 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5145 | |
| 5146 | // FIXME: to do this check properly, we will need to preserve the |
| 5147 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5148 | // base (and therefore couldn't do the check) and a |
| 5149 | // nested-name-qualifier (and therefore could do the lookup). |
| 5150 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5151 | |
| 5152 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5153 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5154 | Old->getOperatorLoc(), |
| 5155 | Old->isArrow(), |
| 5156 | Qualifier, |
| 5157 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5158 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5159 | R, |
| 5160 | (Old->hasExplicitTemplateArgs() |
| 5161 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | template<typename Derived> |
| 5165 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5166 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5170 | template<typename Derived> |
| 5171 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5173 | // FIXME: poor source location |
| 5174 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5175 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5176 | if (EncodedType.isNull()) |
| 5177 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5178 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5179 | if (!getDerived().AlwaysRebuild() && |
| 5180 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5181 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5182 | |
| 5183 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5184 | EncodedType, |
| 5185 | E->getRParenLoc()); |
| 5186 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | template<typename Derived> |
| 5189 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5190 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5191 | // FIXME: Implement this! |
| 5192 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5194 | } |
| 5195 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5196 | template<typename Derived> |
| 5197 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5198 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5200 | } |
| 5201 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | template<typename Derived> |
| 5203 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5204 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5205 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5206 | = cast_or_null<ObjCProtocolDecl>( |
| 5207 | getDerived().TransformDecl(E->getProtocol())); |
| 5208 | if (!Protocol) |
| 5209 | return SemaRef.ExprError(); |
| 5210 | |
| 5211 | if (!getDerived().AlwaysRebuild() && |
| 5212 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | return SemaRef.Owned(E->Retain()); |
| 5214 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5215 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5216 | E->getAtLoc(), |
| 5217 | /*FIXME:*/E->getAtLoc(), |
| 5218 | /*FIXME:*/E->getAtLoc(), |
| 5219 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5221 | } |
| 5222 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | template<typename Derived> |
| 5224 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5225 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5226 | // FIXME: Implement this! |
| 5227 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | } |
| 5230 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | template<typename Derived> |
| 5232 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5233 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5234 | // FIXME: Implement this! |
| 5235 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5237 | } |
| 5238 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5239 | template<typename Derived> |
| 5240 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5241 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5242 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5243 | // FIXME: Implement this! |
| 5244 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5245 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5248 | template<typename Derived> |
| 5249 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5250 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5251 | // FIXME: Implement this! |
| 5252 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5253 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5254 | } |
| 5255 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5256 | template<typename Derived> |
| 5257 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5258 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5259 | // FIXME: Implement this! |
| 5260 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5261 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | template<typename Derived> |
| 5265 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5266 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5267 | bool ArgumentChanged = false; |
| 5268 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5269 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5270 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5271 | if (SubExpr.isInvalid()) |
| 5272 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5273 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5274 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5275 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5276 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5278 | if (!getDerived().AlwaysRebuild() && |
| 5279 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5280 | return SemaRef.Owned(E->Retain()); |
| 5281 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5282 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5283 | move_arg(SubExprs), |
| 5284 | E->getRParenLoc()); |
| 5285 | } |
| 5286 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | template<typename Derived> |
| 5288 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5289 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5290 | // FIXME: Implement this! |
| 5291 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5292 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5295 | template<typename Derived> |
| 5296 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5297 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5298 | // FIXME: Implement this! |
| 5299 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5300 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5303 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5304 | // Type reconstruction |
| 5305 | //===----------------------------------------------------------------------===// |
| 5306 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5307 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5308 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5309 | SourceLocation Star) { |
| 5310 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5311 | getDerived().getBaseEntity()); |
| 5312 | } |
| 5313 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5314 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5315 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5316 | SourceLocation Star) { |
| 5317 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5318 | getDerived().getBaseEntity()); |
| 5319 | } |
| 5320 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5321 | template<typename Derived> |
| 5322 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5323 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5324 | bool WrittenAsLValue, |
| 5325 | SourceLocation Sigil) { |
| 5326 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5327 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5332 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5333 | QualType ClassType, |
| 5334 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5335 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5336 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5341 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5342 | SourceLocation Sigil) { |
| 5343 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5344 | getDerived().getBaseEntity()); |
| 5345 | } |
| 5346 | |
| 5347 | template<typename Derived> |
| 5348 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5349 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5350 | ArrayType::ArraySizeModifier SizeMod, |
| 5351 | const llvm::APInt *Size, |
| 5352 | Expr *SizeExpr, |
| 5353 | unsigned IndexTypeQuals, |
| 5354 | SourceRange BracketsRange) { |
| 5355 | if (SizeExpr || !Size) |
| 5356 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5357 | IndexTypeQuals, BracketsRange, |
| 5358 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5359 | |
| 5360 | QualType Types[] = { |
| 5361 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5362 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5363 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5364 | }; |
| 5365 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5366 | QualType SizeType; |
| 5367 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5368 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5369 | SizeType = Types[I]; |
| 5370 | break; |
| 5371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5372 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5373 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5375 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5378 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5379 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5380 | QualType |
| 5381 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5382 | ArrayType::ArraySizeModifier SizeMod, |
| 5383 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5384 | unsigned IndexTypeQuals, |
| 5385 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5386 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5387 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5391 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5392 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5393 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5394 | unsigned IndexTypeQuals, |
| 5395 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5396 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5397 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5398 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5399 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5400 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | QualType |
| 5402 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5403 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5404 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5405 | unsigned IndexTypeQuals, |
| 5406 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5407 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5408 | SizeExpr.takeAs<Expr>(), |
| 5409 | IndexTypeQuals, BracketsRange); |
| 5410 | } |
| 5411 | |
| 5412 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5413 | QualType |
| 5414 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5415 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5416 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5417 | unsigned IndexTypeQuals, |
| 5418 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5419 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5420 | SizeExpr.takeAs<Expr>(), |
| 5421 | IndexTypeQuals, BracketsRange); |
| 5422 | } |
| 5423 | |
| 5424 | template<typename Derived> |
| 5425 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5426 | unsigned NumElements, |
| 5427 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5428 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5429 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5430 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5431 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5432 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5433 | template<typename Derived> |
| 5434 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5435 | unsigned NumElements, |
| 5436 | SourceLocation AttributeLoc) { |
| 5437 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5438 | NumElements, true); |
| 5439 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5440 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5441 | AttributeLoc); |
| 5442 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5443 | AttributeLoc); |
| 5444 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5445 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5446 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5447 | QualType |
| 5448 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5449 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5450 | SourceLocation AttributeLoc) { |
| 5451 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5452 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5453 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5454 | template<typename Derived> |
| 5455 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5457 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5458 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5459 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5461 | Quals, |
| 5462 | getDerived().getBaseLocation(), |
| 5463 | getDerived().getBaseEntity()); |
| 5464 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5466 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5467 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5468 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5469 | } |
| 5470 | |
| 5471 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5472 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5473 | assert(D && "no decl found"); |
| 5474 | if (D->isInvalidDecl()) return QualType(); |
| 5475 | |
| 5476 | TypeDecl *Ty; |
| 5477 | if (isa<UsingDecl>(D)) { |
| 5478 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5479 | assert(Using->isTypeName() && |
| 5480 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5481 | |
| 5482 | // A valid resolved using typename decl points to exactly one type decl. |
| 5483 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5484 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5485 | |
| 5486 | } else { |
| 5487 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5488 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5489 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5490 | } |
| 5491 | |
| 5492 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5493 | } |
| 5494 | |
| 5495 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5496 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5497 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5498 | } |
| 5499 | |
| 5500 | template<typename Derived> |
| 5501 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5502 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5503 | } |
| 5504 | |
| 5505 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5506 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5507 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5508 | } |
| 5509 | |
| 5510 | template<typename Derived> |
| 5511 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5512 | TemplateName Template, |
| 5513 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5514 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5515 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
| 5519 | NestedNameSpecifier * |
| 5520 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5521 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5522 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5523 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5524 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5525 | CXXScopeSpec SS; |
| 5526 | // FIXME: The source location information is all wrong. |
| 5527 | SS.setRange(Range); |
| 5528 | SS.setScopeRep(Prefix); |
| 5529 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5531 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5532 | ObjectType, |
| 5533 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5534 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | template<typename Derived> |
| 5538 | NestedNameSpecifier * |
| 5539 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5540 | SourceRange Range, |
| 5541 | NamespaceDecl *NS) { |
| 5542 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5543 | } |
| 5544 | |
| 5545 | template<typename Derived> |
| 5546 | NestedNameSpecifier * |
| 5547 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5548 | SourceRange Range, |
| 5549 | bool TemplateKW, |
| 5550 | QualType T) { |
| 5551 | if (T->isDependentType() || T->isRecordType() || |
| 5552 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5553 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5554 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5555 | T.getTypePtr()); |
| 5556 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5557 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5558 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5559 | return 0; |
| 5560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5561 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5562 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5563 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5564 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5565 | bool TemplateKW, |
| 5566 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5568 | Template); |
| 5569 | } |
| 5570 | |
| 5571 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5572 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5573 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5574 | const IdentifierInfo &II, |
| 5575 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5576 | CXXScopeSpec SS; |
| 5577 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5578 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5579 | UnqualifiedId Name; |
| 5580 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5581 | return getSema().ActOnDependentTemplateName( |
| 5582 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5583 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5584 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5585 | ObjectType.getAsOpaquePtr(), |
| 5586 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5587 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5588 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5589 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5590 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5591 | TemplateName |
| 5592 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5593 | OverloadedOperatorKind Operator, |
| 5594 | QualType ObjectType) { |
| 5595 | CXXScopeSpec SS; |
| 5596 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5597 | SS.setScopeRep(Qualifier); |
| 5598 | UnqualifiedId Name; |
| 5599 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5600 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5601 | Operator, SymbolLocations); |
| 5602 | return getSema().ActOnDependentTemplateName( |
| 5603 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5604 | SS, |
| 5605 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5606 | ObjectType.getAsOpaquePtr(), |
| 5607 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5608 | .template getAsVal<TemplateName>(); |
| 5609 | } |
| 5610 | |
| 5611 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5612 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5613 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5614 | SourceLocation OpLoc, |
| 5615 | ExprArg Callee, |
| 5616 | ExprArg First, |
| 5617 | ExprArg Second) { |
| 5618 | Expr *FirstExpr = (Expr *)First.get(); |
| 5619 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5620 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5621 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5624 | if (Op == OO_Subscript) { |
| 5625 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5626 | !SecondExpr->getType()->isOverloadableType()) |
| 5627 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5628 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5629 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5630 | } else if (Op == OO_Arrow) { |
| 5631 | // -> is never a builtin operation. |
| 5632 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5633 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5634 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5635 | // The argument is not of overloadable type, so try to create a |
| 5636 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5638 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5639 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5640 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5641 | } |
| 5642 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | !SecondExpr->getType()->isOverloadableType()) { |
| 5645 | // Neither of the arguments is an overloadable type, so try to |
| 5646 | // create a built-in binary operation. |
| 5647 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5648 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5649 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5650 | if (Result.isInvalid()) |
| 5651 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5653 | First.release(); |
| 5654 | Second.release(); |
| 5655 | return move(Result); |
| 5656 | } |
| 5657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
| 5659 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5660 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5661 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5663 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5664 | assert(ULE->requiresADL()); |
| 5665 | |
| 5666 | // FIXME: Do we have to check |
| 5667 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5668 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5669 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5670 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5671 | } |
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 | // Add any functions found via argument-dependent lookup. |
| 5674 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5675 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5677 | // Create the overloaded operator invocation for unary operators. |
| 5678 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5679 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5680 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5681 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5682 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5683 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5684 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5685 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5686 | OpLoc, |
| 5687 | move(First), |
| 5688 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5692 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5695 | if (Result.isInvalid()) |
| 5696 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5697 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5698 | First.release(); |
| 5699 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5700 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5703 | } // end namespace clang |
| 5704 | |
| 5705 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |