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) { |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 528 | if (NNS->isDependent()) { |
| 529 | CXXScopeSpec SS; |
| 530 | SS.setScopeRep(NNS); |
| 531 | if (!SemaRef.computeDeclContext(SS)) |
| 532 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | ae62889 | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 538 | |
| 539 | /// \brief Build a new typename type that refers to an identifier. |
| 540 | /// |
| 541 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 543 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 545 | const IdentifierInfo *Id, |
| 546 | SourceRange SR) { |
| 547 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 548 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 550 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 551 | /// identifier that names the next step in the nested-name-specifier. |
| 552 | /// |
| 553 | /// By default, performs semantic analysis when building the new |
| 554 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 555 | /// different behavior. |
| 556 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 557 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 558 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 559 | QualType ObjectType, |
| 560 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 561 | |
| 562 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 563 | /// namespace named in the next step in the nested-name-specifier. |
| 564 | /// |
| 565 | /// By default, performs semantic analysis when building the new |
| 566 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 567 | /// different behavior. |
| 568 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 569 | SourceRange Range, |
| 570 | NamespaceDecl *NS); |
| 571 | |
| 572 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 573 | /// type named in the next step in the nested-name-specifier. |
| 574 | /// |
| 575 | /// By default, performs semantic analysis when building the new |
| 576 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 577 | /// different behavior. |
| 578 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 579 | SourceRange Range, |
| 580 | bool TemplateKW, |
| 581 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 582 | |
| 583 | /// \brief Build a new template name given a nested name specifier, a flag |
| 584 | /// indicating whether the "template" keyword was provided, and the template |
| 585 | /// that the template name refers to. |
| 586 | /// |
| 587 | /// By default, builds the new template name directly. Subclasses may override |
| 588 | /// this routine to provide different behavior. |
| 589 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 590 | bool TemplateKW, |
| 591 | TemplateDecl *Template); |
| 592 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 593 | /// \brief Build a new template name given a nested name specifier and the |
| 594 | /// name that is referred to as a template. |
| 595 | /// |
| 596 | /// By default, performs semantic analysis to determine whether the name can |
| 597 | /// be resolved to a specific template, then builds the appropriate kind of |
| 598 | /// template name. Subclasses may override this routine to provide different |
| 599 | /// behavior. |
| 600 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 601 | const IdentifierInfo &II, |
| 602 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 604 | /// \brief Build a new template name given a nested name specifier and the |
| 605 | /// overloaded operator name that is referred to as a template. |
| 606 | /// |
| 607 | /// By default, performs semantic analysis to determine whether the name can |
| 608 | /// be resolved to a specific template, then builds the appropriate kind of |
| 609 | /// template name. Subclasses may override this routine to provide different |
| 610 | /// behavior. |
| 611 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 612 | OverloadedOperatorKind Operator, |
| 613 | QualType ObjectType); |
| 614 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 615 | /// \brief Build a new compound statement. |
| 616 | /// |
| 617 | /// By default, performs semantic analysis to build the new statement. |
| 618 | /// Subclasses may override this routine to provide different behavior. |
| 619 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 620 | MultiStmtArg Statements, |
| 621 | SourceLocation RBraceLoc, |
| 622 | bool IsStmtExpr) { |
| 623 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 624 | IsStmtExpr); |
| 625 | } |
| 626 | |
| 627 | /// \brief Build a new case statement. |
| 628 | /// |
| 629 | /// By default, performs semantic analysis to build the new statement. |
| 630 | /// Subclasses may override this routine to provide different behavior. |
| 631 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 632 | ExprArg LHS, |
| 633 | SourceLocation EllipsisLoc, |
| 634 | ExprArg RHS, |
| 635 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 637 | ColonLoc); |
| 638 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 640 | /// \brief Attach the body to a new case statement. |
| 641 | /// |
| 642 | /// By default, performs semantic analysis to build the new statement. |
| 643 | /// Subclasses may override this routine to provide different behavior. |
| 644 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 645 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 646 | return move(S); |
| 647 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 649 | /// \brief Build a new default statement. |
| 650 | /// |
| 651 | /// By default, performs semantic analysis to build the new statement. |
| 652 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 654 | SourceLocation ColonLoc, |
| 655 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 657 | /*CurScope=*/0); |
| 658 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 660 | /// \brief Build a new label statement. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis to build the new statement. |
| 663 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 665 | IdentifierInfo *Id, |
| 666 | SourceLocation ColonLoc, |
| 667 | StmtArg SubStmt) { |
| 668 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 670 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 671 | /// \brief Build a new "if" statement. |
| 672 | /// |
| 673 | /// By default, performs semantic analysis to build the new statement. |
| 674 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 675 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 676 | VarDecl *CondVar, StmtArg Then, |
| 677 | SourceLocation ElseLoc, StmtArg Else) { |
| 678 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 679 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 682 | /// \brief Start building a new switch statement. |
| 683 | /// |
| 684 | /// By default, performs semantic analysis to build the new statement. |
| 685 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 686 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 687 | VarDecl *CondVar) { |
| 688 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 689 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 691 | /// \brief Attach the body to the switch statement. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis to build the new statement. |
| 694 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 696 | StmtArg Switch, StmtArg Body) { |
| 697 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 698 | move(Body)); |
| 699 | } |
| 700 | |
| 701 | /// \brief Build a new while statement. |
| 702 | /// |
| 703 | /// By default, performs semantic analysis to build the new statement. |
| 704 | /// Subclasses may override this routine to provide different behavior. |
| 705 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 706 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 707 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 708 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 709 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 710 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 713 | /// \brief Build a new do-while statement. |
| 714 | /// |
| 715 | /// By default, performs semantic analysis to build the new statement. |
| 716 | /// Subclasses may override this routine to provide different behavior. |
| 717 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 718 | SourceLocation WhileLoc, |
| 719 | SourceLocation LParenLoc, |
| 720 | ExprArg Cond, |
| 721 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 723 | move(Cond), RParenLoc); |
| 724 | } |
| 725 | |
| 726 | /// \brief Build a new for statement. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis to build the new statement. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 732 | StmtArg Init, Sema::FullExprArg Cond, |
| 733 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 734 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 735 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 736 | DeclPtrTy::make(CondVar), |
| 737 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | /// \brief Build a new goto statement. |
| 741 | /// |
| 742 | /// By default, performs semantic analysis to build the new statement. |
| 743 | /// Subclasses may override this routine to provide different behavior. |
| 744 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 745 | SourceLocation LabelLoc, |
| 746 | LabelStmt *Label) { |
| 747 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 748 | } |
| 749 | |
| 750 | /// \brief Build a new indirect goto statement. |
| 751 | /// |
| 752 | /// By default, performs semantic analysis to build the new statement. |
| 753 | /// Subclasses may override this routine to provide different behavior. |
| 754 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 755 | SourceLocation StarLoc, |
| 756 | ExprArg Target) { |
| 757 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 760 | /// \brief Build a new return statement. |
| 761 | /// |
| 762 | /// By default, performs semantic analysis to build the new statement. |
| 763 | /// Subclasses may override this routine to provide different behavior. |
| 764 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 765 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 767 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 768 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 770 | /// \brief Build a new declaration statement. |
| 771 | /// |
| 772 | /// By default, performs semantic analysis to build the new statement. |
| 773 | /// Subclasses may override this routine to provide different behavior. |
| 774 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | SourceLocation EndLoc) { |
| 777 | return getSema().Owned( |
| 778 | new (getSema().Context) DeclStmt( |
| 779 | DeclGroupRef::Create(getSema().Context, |
| 780 | Decls, NumDecls), |
| 781 | StartLoc, EndLoc)); |
| 782 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 784 | /// \brief Build a new inline asm statement. |
| 785 | /// |
| 786 | /// By default, performs semantic analysis to build the new statement. |
| 787 | /// Subclasses may override this routine to provide different behavior. |
| 788 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 789 | bool IsSimple, |
| 790 | bool IsVolatile, |
| 791 | unsigned NumOutputs, |
| 792 | unsigned NumInputs, |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 793 | IdentifierInfo **Names, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 794 | MultiExprArg Constraints, |
| 795 | MultiExprArg Exprs, |
| 796 | ExprArg AsmString, |
| 797 | MultiExprArg Clobbers, |
| 798 | SourceLocation RParenLoc, |
| 799 | bool MSAsm) { |
| 800 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 801 | NumInputs, Names, move(Constraints), |
| 802 | move(Exprs), move(AsmString), move(Clobbers), |
| 803 | RParenLoc, MSAsm); |
| 804 | } |
| 805 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 806 | /// \brief Build a new C++ exception declaration. |
| 807 | /// |
| 808 | /// By default, performs semantic analysis to build the new decaration. |
| 809 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 810 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 811 | TypeSourceInfo *Declarator, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 812 | IdentifierInfo *Name, |
| 813 | SourceLocation Loc, |
| 814 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 816 | TypeRange); |
| 817 | } |
| 818 | |
| 819 | /// \brief Build a new C++ catch statement. |
| 820 | /// |
| 821 | /// By default, performs semantic analysis to build the new statement. |
| 822 | /// Subclasses may override this routine to provide different behavior. |
| 823 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 824 | VarDecl *ExceptionDecl, |
| 825 | StmtArg Handler) { |
| 826 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 828 | Handler.takeAs<Stmt>())); |
| 829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 831 | /// \brief Build a new C++ try statement. |
| 832 | /// |
| 833 | /// By default, performs semantic analysis to build the new statement. |
| 834 | /// Subclasses may override this routine to provide different behavior. |
| 835 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 836 | StmtArg TryBlock, |
| 837 | MultiStmtArg Handlers) { |
| 838 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 839 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 841 | /// \brief Build a new expression that references a declaration. |
| 842 | /// |
| 843 | /// By default, performs semantic analysis to build the new expression. |
| 844 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 845 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 846 | LookupResult &R, |
| 847 | bool RequiresADL) { |
| 848 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 849 | } |
| 850 | |
| 851 | |
| 852 | /// \brief Build a new expression that references a declaration. |
| 853 | /// |
| 854 | /// By default, performs semantic analysis to build the new expression. |
| 855 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 856 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 857 | SourceRange QualifierRange, |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 858 | ValueDecl *VD, SourceLocation Loc, |
| 859 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 860 | CXXScopeSpec SS; |
| 861 | SS.setScopeRep(Qualifier); |
| 862 | SS.setRange(QualifierRange); |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 863 | |
| 864 | // FIXME: loses template args. |
| 865 | |
| 866 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 867 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 868 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 869 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 871 | /// By default, performs semantic analysis to build the new expression. |
| 872 | /// Subclasses may override this routine to provide different behavior. |
| 873 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 874 | SourceLocation RParen) { |
| 875 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 876 | } |
| 877 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 878 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 880 | /// By default, performs semantic analysis to build the new expression. |
| 881 | /// Subclasses may override this routine to provide different behavior. |
| 882 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 883 | SourceLocation OperatorLoc, |
| 884 | bool isArrow, |
| 885 | SourceLocation DestroyedTypeLoc, |
| 886 | QualType DestroyedType, |
| 887 | NestedNameSpecifier *Qualifier, |
| 888 | SourceRange QualifierRange) { |
| 889 | CXXScopeSpec SS; |
| 890 | if (Qualifier) { |
| 891 | SS.setRange(QualifierRange); |
| 892 | SS.setScopeRep(Qualifier); |
| 893 | } |
| 894 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 895 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 896 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 898 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 899 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 900 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 901 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 902 | OperatorLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 903 | SS, /*FIXME: FirstQualifier*/ 0, |
| 904 | Name, DestroyedTypeLoc, |
| 905 | /*TemplateArgs*/ 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 908 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 910 | /// By default, performs semantic analysis to build the new expression. |
| 911 | /// Subclasses may override this routine to provide different behavior. |
| 912 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 913 | UnaryOperator::Opcode Opc, |
| 914 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 915 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 918 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | /// By default, performs semantic analysis to build the new expression. |
| 921 | /// Subclasses may override this routine to provide different behavior. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 922 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 923 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 924 | bool isSizeOf, SourceRange R) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 925 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 929 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 931 | /// By default, performs semantic analysis to build the new expression. |
| 932 | /// Subclasses may override this routine to provide different behavior. |
| 933 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 934 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 936 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 937 | OpLoc, isSizeOf, R); |
| 938 | if (Result.isInvalid()) |
| 939 | return getSema().ExprError(); |
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 | SubExpr.release(); |
| 942 | return move(Result); |
| 943 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 947 | /// By default, performs semantic analysis to build the new expression. |
| 948 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 949 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 950 | SourceLocation LBracketLoc, |
| 951 | ExprArg RHS, |
| 952 | SourceLocation RBracketLoc) { |
| 953 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 955 | RBracketLoc); |
| 956 | } |
| 957 | |
| 958 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 959 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 960 | /// By default, performs semantic analysis to build the new expression. |
| 961 | /// Subclasses may override this routine to provide different behavior. |
| 962 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 963 | MultiExprArg Args, |
| 964 | SourceLocation *CommaLocs, |
| 965 | SourceLocation RParenLoc) { |
| 966 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 967 | move(Args), CommaLocs, RParenLoc); |
| 968 | } |
| 969 | |
| 970 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 972 | /// By default, performs semantic analysis to build the new expression. |
| 973 | /// Subclasses may override this routine to provide different behavior. |
| 974 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 976 | NestedNameSpecifier *Qualifier, |
| 977 | SourceRange QualifierRange, |
| 978 | SourceLocation MemberLoc, |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 979 | ValueDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 980 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 981 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 982 | if (!Member->getDeclName()) { |
| 983 | // We have a reference to an unnamed field. |
| 984 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 986 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 987 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 988 | return getSema().ExprError(); |
Douglas Gregor | 8aa5f40 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 989 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | MemberExpr *ME = |
Douglas Gregor | 83a56c4 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 991 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 992 | Member, MemberLoc, |
| 993 | cast<FieldDecl>(Member)->getType()); |
| 994 | return getSema().Owned(ME); |
| 995 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 997 | CXXScopeSpec SS; |
| 998 | if (Qualifier) { |
| 999 | SS.setRange(QualifierRange); |
| 1000 | SS.setScopeRep(Qualifier); |
| 1001 | } |
| 1002 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1003 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1004 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1005 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1006 | Sema::LookupMemberName); |
| 1007 | R.addDecl(Member); |
| 1008 | R.resolveKind(); |
| 1009 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1010 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1011 | OpLoc, isArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1012 | SS, FirstQualifierInScope, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1013 | R, ExplicitTemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1018 | /// By default, performs semantic analysis to build the new expression. |
| 1019 | /// Subclasses may override this routine to provide different behavior. |
| 1020 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1021 | BinaryOperator::Opcode Opc, |
| 1022 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1023 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1024 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1029 | /// By default, performs semantic analysis to build the new expression. |
| 1030 | /// Subclasses may override this routine to provide different behavior. |
| 1031 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1032 | SourceLocation QuestionLoc, |
| 1033 | ExprArg LHS, |
| 1034 | SourceLocation ColonLoc, |
| 1035 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | move(LHS), move(RHS)); |
| 1038 | } |
| 1039 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1040 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | /// By default, performs semantic analysis to build the new expression. |
| 1043 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1044 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1045 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | SourceLocation RParenLoc, |
| 1047 | ExprArg SubExpr) { |
John McCall | b042fdf | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1048 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1049 | move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1051 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1052 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | /// By default, performs semantic analysis to build the new expression. |
| 1055 | /// Subclasses may override this routine to provide different behavior. |
| 1056 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1057 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | SourceLocation RParenLoc, |
| 1059 | ExprArg Init) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1060 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1061 | move(Init)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1064 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1065 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1066 | /// By default, performs semantic analysis to build the new expression. |
| 1067 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1069 | SourceLocation OpLoc, |
| 1070 | SourceLocation AccessorLoc, |
| 1071 | IdentifierInfo &Accessor) { |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1072 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1073 | CXXScopeSpec SS; |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1074 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1075 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1076 | OpLoc, /*IsArrow*/ false, |
| 1077 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1078 | DeclarationName(&Accessor), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1079 | AccessorLoc, |
| 1080 | /* TemplateArgs */ 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1081 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1083 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1085 | /// By default, performs semantic analysis to build the new expression. |
| 1086 | /// Subclasses may override this routine to provide different behavior. |
| 1087 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1088 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1089 | SourceLocation RBraceLoc, |
| 1090 | QualType ResultTy) { |
| 1091 | OwningExprResult Result |
| 1092 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1093 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1094 | return move(Result); |
| 1095 | |
| 1096 | // Patch in the result type we were given, which may have been computed |
| 1097 | // when the initial InitListExpr was built. |
| 1098 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1099 | ILE->setType(ResultTy); |
| 1100 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1105 | /// By default, performs semantic analysis to build the new expression. |
| 1106 | /// Subclasses may override this routine to provide different behavior. |
| 1107 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1108 | MultiExprArg ArrayExprs, |
| 1109 | SourceLocation EqualOrColonLoc, |
| 1110 | bool GNUSyntax, |
| 1111 | ExprArg Init) { |
| 1112 | OwningExprResult Result |
| 1113 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1114 | move(Init)); |
| 1115 | if (Result.isInvalid()) |
| 1116 | return SemaRef.ExprError(); |
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 | ArrayExprs.release(); |
| 1119 | return move(Result); |
| 1120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1123 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1124 | /// By default, builds the implicit value initialization without performing |
| 1125 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1126 | /// different behavior. |
| 1127 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1128 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1129 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1130 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1131 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1133 | /// By default, performs semantic analysis to build the new expression. |
| 1134 | /// Subclasses may override this routine to provide different behavior. |
| 1135 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1136 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | RParenLoc); |
| 1139 | } |
| 1140 | |
| 1141 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1143 | /// By default, performs semantic analysis to build the new expression. |
| 1144 | /// Subclasses may override this routine to provide different behavior. |
| 1145 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1146 | MultiExprArg SubExprs, |
| 1147 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1148 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1149 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1152 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | /// |
| 1154 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1155 | /// rather than attempting to map the label statement itself. |
| 1156 | /// Subclasses may override this routine to provide different behavior. |
| 1157 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1158 | SourceLocation LabelLoc, |
| 1159 | LabelStmt *Label) { |
| 1160 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1163 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1165 | /// By default, performs semantic analysis to build the new expression. |
| 1166 | /// Subclasses may override this routine to provide different behavior. |
| 1167 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1168 | StmtArg SubStmt, |
| 1169 | SourceLocation RParenLoc) { |
| 1170 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1171 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1173 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1174 | /// |
| 1175 | /// By default, performs semantic analysis to build the new expression. |
| 1176 | /// Subclasses may override this routine to provide different behavior. |
| 1177 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1178 | QualType T1, QualType T2, |
| 1179 | SourceLocation RParenLoc) { |
| 1180 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1181 | T1.getAsOpaquePtr(), |
| 1182 | T2.getAsOpaquePtr(), |
| 1183 | RParenLoc); |
| 1184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1186 | /// \brief Build a new __builtin_choose_expr expression. |
| 1187 | /// |
| 1188 | /// By default, performs semantic analysis to build the new expression. |
| 1189 | /// Subclasses may override this routine to provide different behavior. |
| 1190 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1191 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1192 | SourceLocation RParenLoc) { |
| 1193 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1194 | move(Cond), move(LHS), move(RHS), |
| 1195 | RParenLoc); |
| 1196 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1198 | /// \brief Build a new overloaded operator call expression. |
| 1199 | /// |
| 1200 | /// By default, performs semantic analysis to build the new expression. |
| 1201 | /// The semantic analysis provides the behavior of template instantiation, |
| 1202 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1204 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1205 | /// provide different behavior. |
| 1206 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1207 | SourceLocation OpLoc, |
| 1208 | ExprArg Callee, |
| 1209 | ExprArg First, |
| 1210 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | |
| 1212 | /// \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] | 1213 | /// reinterpret_cast. |
| 1214 | /// |
| 1215 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | /// Subclasses may override this routine to provide different behavior. |
| 1218 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1219 | Stmt::StmtClass Class, |
| 1220 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1221 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | SourceLocation RAngleLoc, |
| 1223 | SourceLocation LParenLoc, |
| 1224 | ExprArg SubExpr, |
| 1225 | SourceLocation RParenLoc) { |
| 1226 | switch (Class) { |
| 1227 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1228 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | move(SubExpr), RParenLoc); |
| 1231 | |
| 1232 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1233 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1235 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1238 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | RAngleLoc, LParenLoc, |
| 1240 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | case Stmt::CXXConstCastExprClass: |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1244 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1246 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | default: |
| 1249 | assert(false && "Invalid C++ named cast"); |
| 1250 | break; |
| 1251 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1252 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1253 | return getSema().ExprError(); |
| 1254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1255 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1256 | /// \brief Build a new C++ static_cast expression. |
| 1257 | /// |
| 1258 | /// By default, performs semantic analysis to build the new expression. |
| 1259 | /// Subclasses may override this routine to provide different behavior. |
| 1260 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1261 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1262 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | SourceLocation RAngleLoc, |
| 1264 | SourceLocation LParenLoc, |
| 1265 | ExprArg SubExpr, |
| 1266 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1267 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1268 | TInfo, move(SubExpr), |
| 1269 | SourceRange(LAngleLoc, RAngleLoc), |
| 1270 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | /// \brief Build a new C++ dynamic_cast expression. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new expression. |
| 1276 | /// Subclasses may override this routine to provide different behavior. |
| 1277 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1278 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1279 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | SourceLocation RAngleLoc, |
| 1281 | SourceLocation LParenLoc, |
| 1282 | ExprArg SubExpr, |
| 1283 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1284 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1285 | TInfo, move(SubExpr), |
| 1286 | SourceRange(LAngleLoc, RAngleLoc), |
| 1287 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1291 | /// |
| 1292 | /// By default, performs semantic analysis to build the new expression. |
| 1293 | /// Subclasses may override this routine to provide different behavior. |
| 1294 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1295 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1296 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1297 | SourceLocation RAngleLoc, |
| 1298 | SourceLocation LParenLoc, |
| 1299 | ExprArg SubExpr, |
| 1300 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1301 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1302 | TInfo, move(SubExpr), |
| 1303 | SourceRange(LAngleLoc, RAngleLoc), |
| 1304 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /// \brief Build a new C++ const_cast expression. |
| 1308 | /// |
| 1309 | /// By default, performs semantic analysis to build the new expression. |
| 1310 | /// Subclasses may override this routine to provide different behavior. |
| 1311 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1312 | SourceLocation LAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1313 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | SourceLocation RAngleLoc, |
| 1315 | SourceLocation LParenLoc, |
| 1316 | ExprArg SubExpr, |
| 1317 | SourceLocation RParenLoc) { |
John McCall | c89724c | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1318 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1319 | TInfo, move(SubExpr), |
| 1320 | SourceRange(LAngleLoc, RAngleLoc), |
| 1321 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | /// \brief Build a new C++ functional-style cast expression. |
| 1325 | /// |
| 1326 | /// By default, performs semantic analysis to build the new expression. |
| 1327 | /// Subclasses may override this routine to provide different behavior. |
| 1328 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1329 | TypeSourceInfo *TInfo, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | SourceLocation LParenLoc, |
| 1331 | ExprArg SubExpr, |
| 1332 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1333 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1335 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1337 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | RParenLoc); |
| 1340 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | /// \brief Build a new C++ typeid(type) expression. |
| 1343 | /// |
| 1344 | /// By default, performs semantic analysis to build the new expression. |
| 1345 | /// Subclasses may override this routine to provide different behavior. |
| 1346 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1347 | SourceLocation LParenLoc, |
| 1348 | QualType T, |
| 1349 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1351 | T.getAsOpaquePtr(), RParenLoc); |
| 1352 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1354 | /// \brief Build a new C++ typeid(expr) expression. |
| 1355 | /// |
| 1356 | /// By default, performs semantic analysis to build the new expression. |
| 1357 | /// Subclasses may override this routine to provide different behavior. |
| 1358 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1359 | SourceLocation LParenLoc, |
| 1360 | ExprArg Operand, |
| 1361 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1364 | RParenLoc); |
| 1365 | if (Result.isInvalid()) |
| 1366 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1369 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | /// \brief Build a new C++ "this" expression. |
| 1373 | /// |
| 1374 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1378 | QualType ThisType, |
| 1379 | bool isImplicit) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | return getSema().Owned( |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1381 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1382 | isImplicit)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /// \brief Build a new C++ throw expression. |
| 1386 | /// |
| 1387 | /// By default, performs semantic analysis to build the new expression. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
| 1389 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1390 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1391 | } |
| 1392 | |
| 1393 | /// \brief Build a new C++ default-argument expression. |
| 1394 | /// |
| 1395 | /// By default, builds a new default-argument expression, which does not |
| 1396 | /// require any semantic analysis. Subclasses may override this routine to |
| 1397 | /// provide different behavior. |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1398 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1399 | ParmVarDecl *Param) { |
| 1400 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1401 | Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /// \brief Build a new C++ zero-initialization expression. |
| 1405 | /// |
| 1406 | /// By default, performs semantic analysis to build the new expression. |
| 1407 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | SourceLocation LParenLoc, |
| 1410 | QualType T, |
| 1411 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1413 | T.getAsOpaquePtr(), LParenLoc, |
| 1414 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | 0, RParenLoc); |
| 1416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | /// \brief Build a new C++ "new" expression. |
| 1419 | /// |
| 1420 | /// By default, performs semantic analysis to build the new expression. |
| 1421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | bool UseGlobal, |
| 1424 | SourceLocation PlacementLParen, |
| 1425 | MultiExprArg PlacementArgs, |
| 1426 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | QualType AllocType, |
| 1429 | SourceLocation TypeLoc, |
| 1430 | SourceRange TypeRange, |
| 1431 | ExprArg ArraySize, |
| 1432 | SourceLocation ConstructorLParen, |
| 1433 | MultiExprArg ConstructorArgs, |
| 1434 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | PlacementLParen, |
| 1437 | move(PlacementArgs), |
| 1438 | PlacementRParen, |
| 1439 | ParenTypeId, |
| 1440 | AllocType, |
| 1441 | TypeLoc, |
| 1442 | TypeRange, |
| 1443 | move(ArraySize), |
| 1444 | ConstructorLParen, |
| 1445 | move(ConstructorArgs), |
| 1446 | ConstructorRParen); |
| 1447 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1449 | /// \brief Build a new C++ "delete" expression. |
| 1450 | /// |
| 1451 | /// By default, performs semantic analysis to build the new expression. |
| 1452 | /// Subclasses may override this routine to provide different behavior. |
| 1453 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1454 | bool IsGlobalDelete, |
| 1455 | bool IsArrayForm, |
| 1456 | ExprArg Operand) { |
| 1457 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1458 | move(Operand)); |
| 1459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1460 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1461 | /// \brief Build a new unary type trait expression. |
| 1462 | /// |
| 1463 | /// By default, performs semantic analysis to build the new expression. |
| 1464 | /// Subclasses may override this routine to provide different behavior. |
| 1465 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1466 | SourceLocation StartLoc, |
| 1467 | SourceLocation LParenLoc, |
| 1468 | QualType T, |
| 1469 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1470 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | T.getAsOpaquePtr(), RParenLoc); |
| 1472 | } |
| 1473 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | /// expression. |
| 1476 | /// |
| 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1479 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | SourceRange QualifierRange, |
| 1481 | DeclarationName Name, |
| 1482 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1483 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | CXXScopeSpec SS; |
| 1485 | SS.setRange(QualifierRange); |
| 1486 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1487 | |
| 1488 | if (TemplateArgs) |
| 1489 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1490 | *TemplateArgs); |
| 1491 | |
| 1492 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /// \brief Build a new template-id expression. |
| 1496 | /// |
| 1497 | /// By default, performs semantic analysis to build the new expression. |
| 1498 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1499 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1500 | LookupResult &R, |
| 1501 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1502 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1503 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /// \brief Build a new object-construction expression. |
| 1507 | /// |
| 1508 | /// By default, performs semantic analysis to build the new expression. |
| 1509 | /// Subclasses may override this routine to provide different behavior. |
| 1510 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1511 | SourceLocation Loc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | CXXConstructorDecl *Constructor, |
| 1513 | bool IsElidable, |
| 1514 | MultiExprArg Args) { |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1515 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1516 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1517 | ConvertedArgs)) |
| 1518 | return getSema().ExprError(); |
| 1519 | |
| 1520 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1521 | move_arg(ConvertedArgs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /// \brief Build a new object-construction expression. |
| 1525 | /// |
| 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
| 1528 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1529 | QualType T, |
| 1530 | SourceLocation LParenLoc, |
| 1531 | MultiExprArg Args, |
| 1532 | SourceLocation *Commas, |
| 1533 | SourceLocation RParenLoc) { |
| 1534 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1535 | T.getAsOpaquePtr(), |
| 1536 | LParenLoc, |
| 1537 | move(Args), |
| 1538 | Commas, |
| 1539 | RParenLoc); |
| 1540 | } |
| 1541 | |
| 1542 | /// \brief Build a new object-construction expression. |
| 1543 | /// |
| 1544 | /// By default, performs semantic analysis to build the new expression. |
| 1545 | /// Subclasses may override this routine to provide different behavior. |
| 1546 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1547 | QualType T, |
| 1548 | SourceLocation LParenLoc, |
| 1549 | MultiExprArg Args, |
| 1550 | SourceLocation *Commas, |
| 1551 | SourceLocation RParenLoc) { |
| 1552 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1553 | /*FIXME*/LParenLoc), |
| 1554 | T.getAsOpaquePtr(), |
| 1555 | LParenLoc, |
| 1556 | move(Args), |
| 1557 | Commas, |
| 1558 | RParenLoc); |
| 1559 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | /// \brief Build a new member reference expression. |
| 1562 | /// |
| 1563 | /// By default, performs semantic analysis to build the new expression. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1565 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1566 | QualType BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1567 | bool IsArrow, |
| 1568 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1569 | NestedNameSpecifier *Qualifier, |
| 1570 | SourceRange QualifierRange, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1571 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1572 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1573 | SourceLocation MemberLoc, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1574 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1575 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1576 | SS.setRange(QualifierRange); |
| 1577 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1579 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1580 | OperatorLoc, IsArrow, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1581 | SS, FirstQualifierInScope, |
| 1582 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1585 | /// \brief Build a new member reference expression. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1586 | /// |
| 1587 | /// By default, performs semantic analysis to build the new expression. |
| 1588 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1589 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1590 | QualType BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1591 | SourceLocation OperatorLoc, |
| 1592 | bool IsArrow, |
| 1593 | NestedNameSpecifier *Qualifier, |
| 1594 | SourceRange QualifierRange, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1595 | NamedDecl *FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1596 | LookupResult &R, |
| 1597 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1598 | CXXScopeSpec SS; |
| 1599 | SS.setRange(QualifierRange); |
| 1600 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1602 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1603 | OperatorLoc, IsArrow, |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1604 | SS, FirstQualifierInScope, |
| 1605 | R, TemplateArgs); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1606 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1608 | /// \brief Build a new Objective-C @encode expression. |
| 1609 | /// |
| 1610 | /// By default, performs semantic analysis to build the new expression. |
| 1611 | /// Subclasses may override this routine to provide different behavior. |
| 1612 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1613 | QualType T, |
| 1614 | SourceLocation RParenLoc) { |
| 1615 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1616 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1618 | |
| 1619 | /// \brief Build a new Objective-C protocol expression. |
| 1620 | /// |
| 1621 | /// By default, performs semantic analysis to build the new expression. |
| 1622 | /// Subclasses may override this routine to provide different behavior. |
| 1623 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1624 | SourceLocation AtLoc, |
| 1625 | SourceLocation ProtoLoc, |
| 1626 | SourceLocation LParenLoc, |
| 1627 | SourceLocation RParenLoc) { |
| 1628 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1629 | Protocol->getIdentifier(), |
| 1630 | AtLoc, |
| 1631 | ProtoLoc, |
| 1632 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | /// \brief Build a new shuffle vector expression. |
| 1637 | /// |
| 1638 | /// By default, performs semantic analysis to build the new expression. |
| 1639 | /// Subclasses may override this routine to provide different behavior. |
| 1640 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1641 | MultiExprArg SubExprs, |
| 1642 | SourceLocation RParenLoc) { |
| 1643 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1646 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1647 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1648 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | // Build a reference to the __builtin_shufflevector builtin |
| 1651 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1654 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1656 | |
| 1657 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | unsigned NumSubExprs = SubExprs.size(); |
| 1659 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1660 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1661 | Subs, NumSubExprs, |
| 1662 | Builtin->getResultType(), |
| 1663 | RParenLoc); |
| 1664 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | // Type-check the __builtin_shufflevector expression. |
| 1667 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1668 | if (Result.isInvalid()) |
| 1669 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1672 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1674 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1676 | template<typename Derived> |
| 1677 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1678 | if (!S) |
| 1679 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1681 | switch (S->getStmtClass()) { |
| 1682 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1683 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1684 | // Transform individual statement nodes |
| 1685 | #define STMT(Node, Parent) \ |
| 1686 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1687 | #define EXPR(Node, Parent) |
| 1688 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1690 | // Transform expressions by calling TransformExpr. |
| 1691 | #define STMT(Node, Parent) |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1692 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1693 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1694 | #include "clang/AST/StmtNodes.def" |
| 1695 | { |
| 1696 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1697 | if (E.isInvalid()) |
| 1698 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1699 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1700 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1701 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1704 | return SemaRef.Owned(S->Retain()); |
| 1705 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1706 | |
| 1707 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1708 | template<typename Derived> |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1709 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | if (!E) |
| 1711 | return SemaRef.Owned(E); |
| 1712 | |
| 1713 | switch (E->getStmtClass()) { |
| 1714 | case Stmt::NoStmtClass: break; |
| 1715 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1716 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1717 | #define EXPR(Node, Parent) \ |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1718 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1719 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1726 | NestedNameSpecifier * |
| 1727 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1728 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1729 | QualType ObjectType, |
| 1730 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1731 | if (!NNS) |
| 1732 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1734 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1735 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1736 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1738 | ObjectType, |
| 1739 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1740 | if (!Prefix) |
| 1741 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1742 | |
| 1743 | // 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] | 1744 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1745 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1746 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1747 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1749 | switch (NNS->getKind()) { |
| 1750 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1752 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1753 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1754 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1755 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
| 1757 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1758 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1759 | ObjectType, |
| 1760 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1762 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1764 | = cast_or_null<NamespaceDecl>( |
| 1765 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | Prefix == NNS->getPrefix() && |
| 1768 | NS == NNS->getAsNamespace()) |
| 1769 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1770 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1771 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1772 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1774 | case NestedNameSpecifier::Global: |
| 1775 | // There is no meaningful transformation that one could perform on the |
| 1776 | // global scope. |
| 1777 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1779 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1780 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1781 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1782 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1783 | if (T.isNull()) |
| 1784 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1785 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1786 | if (!getDerived().AlwaysRebuild() && |
| 1787 | Prefix == NNS->getPrefix() && |
| 1788 | T == QualType(NNS->getAsType(), 0)) |
| 1789 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | |
| 1791 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1792 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1793 | T); |
| 1794 | } |
| 1795 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1797 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1802 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1803 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1804 | SourceLocation Loc, |
| 1805 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | if (!Name) |
| 1807 | return Name; |
| 1808 | |
| 1809 | switch (Name.getNameKind()) { |
| 1810 | case DeclarationName::Identifier: |
| 1811 | case DeclarationName::ObjCZeroArgSelector: |
| 1812 | case DeclarationName::ObjCOneArgSelector: |
| 1813 | case DeclarationName::ObjCMultiArgSelector: |
| 1814 | case DeclarationName::CXXOperatorName: |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1815 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1816 | case DeclarationName::CXXUsingDirective: |
| 1817 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1819 | case DeclarationName::CXXConstructorName: |
| 1820 | case DeclarationName::CXXDestructorName: |
| 1821 | case DeclarationName::CXXConversionFunctionName: { |
| 1822 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1823 | QualType T; |
| 1824 | if (!ObjectType.isNull() && |
| 1825 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1826 | TemplateSpecializationType *SpecType |
| 1827 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1828 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1829 | } else |
| 1830 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1831 | if (T.isNull()) |
| 1832 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1833 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1834 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1836 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1837 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1840 | return DeclarationName(); |
| 1841 | } |
| 1842 | |
| 1843 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1845 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1846 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1847 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1848 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1849 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1850 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1851 | if (!NNS) |
| 1852 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1853 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1854 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1856 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1857 | if (!TransTemplate) |
| 1858 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1860 | if (!getDerived().AlwaysRebuild() && |
| 1861 | NNS == QTN->getQualifier() && |
| 1862 | TransTemplate == Template) |
| 1863 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1865 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1866 | TransTemplate); |
| 1867 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1869 | // These should be getting filtered out before they make it into the AST. |
| 1870 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1871 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1873 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1875 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1876 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1877 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1880 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1881 | NNS == DTN->getQualifier() && |
| 1882 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1883 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1884 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1885 | if (DTN->isIdentifier()) |
| 1886 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1887 | ObjectType); |
| 1888 | |
| 1889 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1890 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1893 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1895 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1896 | if (!TransTemplate) |
| 1897 | return TemplateName(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 1900 | TransTemplate == Template) |
| 1901 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1902 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1903 | return TemplateName(TransTemplate); |
| 1904 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1905 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1906 | // These should be getting filtered out before they reach the AST. |
| 1907 | assert(false && "overloaded function decl survived to here"); |
| 1908 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1912 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1913 | const TemplateArgument &Arg, |
| 1914 | TemplateArgumentLoc &Output) { |
| 1915 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1916 | switch (Arg.getKind()) { |
| 1917 | case TemplateArgument::Null: |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1918 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | |
| 1921 | case TemplateArgument::Type: |
| 1922 | Output = TemplateArgumentLoc(Arg, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1923 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1924 | |
| 1925 | break; |
| 1926 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1927 | case TemplateArgument::Template: |
| 1928 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1929 | break; |
| 1930 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1931 | case TemplateArgument::Expression: |
| 1932 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1933 | break; |
| 1934 | |
| 1935 | case TemplateArgument::Declaration: |
| 1936 | case TemplateArgument::Integral: |
| 1937 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1938 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1939 | break; |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | template<typename Derived> |
| 1944 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1945 | const TemplateArgumentLoc &Input, |
| 1946 | TemplateArgumentLoc &Output) { |
| 1947 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1948 | switch (Arg.getKind()) { |
| 1949 | case TemplateArgument::Null: |
| 1950 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1951 | Output = Input; |
| 1952 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1954 | case TemplateArgument::Type: { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1955 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1956 | if (DI == NULL) |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1957 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1958 | |
| 1959 | DI = getDerived().TransformType(DI); |
| 1960 | if (!DI) return true; |
| 1961 | |
| 1962 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1963 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1964 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1966 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1967 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1968 | DeclarationName Name; |
| 1969 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1970 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1971 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1972 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1973 | if (!D) return true; |
| 1974 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1975 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1976 | if (SourceExpr) { |
| 1977 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1978 | Action::Unevaluated); |
| 1979 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1980 | if (E.isInvalid()) |
| 1981 | SourceExpr = NULL; |
| 1982 | else { |
| 1983 | SourceExpr = E.takeAs<Expr>(); |
| 1984 | SourceExpr->Retain(); |
| 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1989 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1991 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1992 | case TemplateArgument::Template: { |
| 1993 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1994 | TemplateName Template |
| 1995 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1996 | if (Template.isNull()) |
| 1997 | return true; |
| 1998 | |
| 1999 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2000 | Input.getTemplateQualifierRange(), |
| 2001 | Input.getTemplateNameLoc()); |
| 2002 | return false; |
| 2003 | } |
| 2004 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2005 | case TemplateArgument::Expression: { |
| 2006 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2008 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2010 | Expr *InputExpr = Input.getSourceExpression(); |
| 2011 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2012 | |
| 2013 | Sema::OwningExprResult E |
| 2014 | = getDerived().TransformExpr(InputExpr); |
| 2015 | if (E.isInvalid()) return true; |
| 2016 | |
| 2017 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2018 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2019 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2020 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2023 | case TemplateArgument::Pack: { |
| 2024 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2025 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2026 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2027 | AEnd = Arg.pack_end(); |
| 2028 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2030 | // FIXME: preserve source information here when we start |
| 2031 | // caring about parameter packs. |
| 2032 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2033 | TemplateArgumentLoc InputArg; |
| 2034 | TemplateArgumentLoc OutputArg; |
| 2035 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2036 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2037 | return true; |
| 2038 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2039 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2040 | } |
| 2041 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2042 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2043 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2044 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2045 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2046 | } |
| 2047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2049 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2050 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2053 | //===----------------------------------------------------------------------===// |
| 2054 | // Type transformation |
| 2055 | //===----------------------------------------------------------------------===// |
| 2056 | |
| 2057 | template<typename Derived> |
| 2058 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2059 | if (getDerived().AlreadyTransformed(T)) |
| 2060 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2061 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2062 | // Temporary workaround. All of these transformations should |
| 2063 | // eventually turn into transformations on TypeLocs. |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2064 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2065 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2066 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2067 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2068 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2069 | if (!NewDI) |
| 2070 | return QualType(); |
| 2071 | |
| 2072 | return NewDI->getType(); |
| 2073 | } |
| 2074 | |
| 2075 | template<typename Derived> |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2076 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2077 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2078 | return DI; |
| 2079 | |
| 2080 | TypeLocBuilder TLB; |
| 2081 | |
| 2082 | TypeLoc TL = DI->getTypeLoc(); |
| 2083 | TLB.reserve(TL.getFullDataSize()); |
| 2084 | |
| 2085 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2086 | if (Result.isNull()) |
| 2087 | return 0; |
| 2088 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2089 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | template<typename Derived> |
| 2093 | QualType |
| 2094 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2095 | switch (T.getTypeLocClass()) { |
| 2096 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2097 | #define TYPELOC(CLASS, PARENT) \ |
| 2098 | case TypeLoc::CLASS: \ |
| 2099 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2100 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2103 | llvm_unreachable("unhandled type loc!"); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2104 | return QualType(); |
| 2105 | } |
| 2106 | |
| 2107 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2108 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2109 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2110 | /// types). This is the right thing for template instantiation, but |
| 2111 | /// probably not for other clients. |
| 2112 | template<typename Derived> |
| 2113 | QualType |
| 2114 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2115 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2116 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2117 | |
| 2118 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2119 | if (Result.isNull()) |
| 2120 | return QualType(); |
| 2121 | |
| 2122 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2123 | // FIXME: this is the right thing for template instantiation, but |
| 2124 | // probably not for other clients. |
| 2125 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2126 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2127 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2128 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2129 | |
| 2130 | TLB.push<QualifiedTypeLoc>(Result); |
| 2131 | |
| 2132 | // No location information to preserve. |
| 2133 | |
| 2134 | return Result; |
| 2135 | } |
| 2136 | |
| 2137 | template <class TyLoc> static inline |
| 2138 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2139 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2140 | NewT.setNameLoc(T.getNameLoc()); |
| 2141 | return T.getType(); |
| 2142 | } |
| 2143 | |
| 2144 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2145 | // the equivalent template version work. |
| 2146 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2147 | QualType PointeeType \ |
| 2148 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2149 | if (PointeeType.isNull()) \ |
| 2150 | return QualType(); \ |
| 2151 | \ |
| 2152 | QualType Result = TL.getType(); \ |
| 2153 | if (getDerived().AlwaysRebuild() || \ |
| 2154 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2155 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2156 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2157 | if (Result.isNull()) \ |
| 2158 | return QualType(); \ |
| 2159 | } \ |
| 2160 | \ |
| 2161 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2162 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2163 | \ |
| 2164 | return Result; \ |
| 2165 | } while(0) |
| 2166 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2167 | template<typename Derived> |
| 2168 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2169 | BuiltinTypeLoc T) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2170 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2171 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2172 | if (T.needsExtraLocalData()) |
| 2173 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2174 | return T.getType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2177 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2178 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2179 | ComplexTypeLoc T) { |
| 2180 | // FIXME: recurse? |
| 2181 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2182 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2184 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2185 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2186 | PointerTypeLoc TL) { |
| 2187 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2188 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2189 | |
| 2190 | template<typename Derived> |
| 2191 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2192 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2193 | BlockPointerTypeLoc TL) { |
| 2194 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2197 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2198 | /// don't care whether the type itself is an l-value type or an r-value |
| 2199 | /// type; we only care if the type was *written* as an l-value type |
| 2200 | /// or an r-value type. |
| 2201 | template<typename Derived> |
| 2202 | QualType |
| 2203 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2204 | ReferenceTypeLoc TL) { |
| 2205 | const ReferenceType *T = TL.getTypePtr(); |
| 2206 | |
| 2207 | // Note that this works with the pointee-as-written. |
| 2208 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2209 | if (PointeeType.isNull()) |
| 2210 | return QualType(); |
| 2211 | |
| 2212 | QualType Result = TL.getType(); |
| 2213 | if (getDerived().AlwaysRebuild() || |
| 2214 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2215 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2216 | T->isSpelledAsLValue(), |
| 2217 | TL.getSigilLoc()); |
| 2218 | if (Result.isNull()) |
| 2219 | return QualType(); |
| 2220 | } |
| 2221 | |
| 2222 | // r-value references can be rebuilt as l-value references. |
| 2223 | ReferenceTypeLoc NewTL; |
| 2224 | if (isa<LValueReferenceType>(Result)) |
| 2225 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2226 | else |
| 2227 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2228 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2229 | |
| 2230 | return Result; |
| 2231 | } |
| 2232 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | template<typename Derived> |
| 2234 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2235 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2236 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2237 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2240 | template<typename Derived> |
| 2241 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2242 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2243 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2244 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2245 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2247 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2248 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2249 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2250 | MemberPointerTypeLoc TL) { |
| 2251 | MemberPointerType *T = TL.getTypePtr(); |
| 2252 | |
| 2253 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2254 | if (PointeeType.isNull()) |
| 2255 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2256 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2257 | // TODO: preserve source information for this. |
| 2258 | QualType ClassType |
| 2259 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2260 | if (ClassType.isNull()) |
| 2261 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2262 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2263 | QualType Result = TL.getType(); |
| 2264 | if (getDerived().AlwaysRebuild() || |
| 2265 | PointeeType != T->getPointeeType() || |
| 2266 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2267 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2268 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2269 | if (Result.isNull()) |
| 2270 | return QualType(); |
| 2271 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2272 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2273 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2274 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2275 | |
| 2276 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2279 | template<typename Derived> |
| 2280 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2281 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2282 | ConstantArrayTypeLoc TL) { |
| 2283 | ConstantArrayType *T = TL.getTypePtr(); |
| 2284 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2285 | if (ElementType.isNull()) |
| 2286 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2287 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2288 | QualType Result = TL.getType(); |
| 2289 | if (getDerived().AlwaysRebuild() || |
| 2290 | ElementType != T->getElementType()) { |
| 2291 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2292 | T->getSizeModifier(), |
| 2293 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2294 | T->getIndexTypeCVRQualifiers(), |
| 2295 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2296 | if (Result.isNull()) |
| 2297 | return QualType(); |
| 2298 | } |
| 2299 | |
| 2300 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2301 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2302 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2304 | Expr *Size = TL.getSizeExpr(); |
| 2305 | if (Size) { |
| 2306 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2307 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2308 | } |
| 2309 | NewTL.setSizeExpr(Size); |
| 2310 | |
| 2311 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2313 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2314 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2315 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2316 | TypeLocBuilder &TLB, |
| 2317 | IncompleteArrayTypeLoc TL) { |
| 2318 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2319 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2320 | if (ElementType.isNull()) |
| 2321 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2322 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2323 | QualType Result = TL.getType(); |
| 2324 | if (getDerived().AlwaysRebuild() || |
| 2325 | ElementType != T->getElementType()) { |
| 2326 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2327 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2328 | T->getIndexTypeCVRQualifiers(), |
| 2329 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2330 | if (Result.isNull()) |
| 2331 | return QualType(); |
| 2332 | } |
| 2333 | |
| 2334 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2335 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2336 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2337 | NewTL.setSizeExpr(0); |
| 2338 | |
| 2339 | return Result; |
| 2340 | } |
| 2341 | |
| 2342 | template<typename Derived> |
| 2343 | QualType |
| 2344 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2345 | VariableArrayTypeLoc TL) { |
| 2346 | VariableArrayType *T = TL.getTypePtr(); |
| 2347 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2348 | if (ElementType.isNull()) |
| 2349 | return QualType(); |
| 2350 | |
| 2351 | // Array bounds are not potentially evaluated contexts |
| 2352 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2353 | |
| 2354 | Sema::OwningExprResult SizeResult |
| 2355 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2356 | if (SizeResult.isInvalid()) |
| 2357 | return QualType(); |
| 2358 | |
| 2359 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2360 | |
| 2361 | QualType Result = TL.getType(); |
| 2362 | if (getDerived().AlwaysRebuild() || |
| 2363 | ElementType != T->getElementType() || |
| 2364 | Size != T->getSizeExpr()) { |
| 2365 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2366 | T->getSizeModifier(), |
| 2367 | move(SizeResult), |
| 2368 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2369 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2370 | if (Result.isNull()) |
| 2371 | return QualType(); |
| 2372 | } |
| 2373 | else SizeResult.take(); |
| 2374 | |
| 2375 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2376 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2377 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2378 | NewTL.setSizeExpr(Size); |
| 2379 | |
| 2380 | return Result; |
| 2381 | } |
| 2382 | |
| 2383 | template<typename Derived> |
| 2384 | QualType |
| 2385 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2386 | DependentSizedArrayTypeLoc TL) { |
| 2387 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2388 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2389 | if (ElementType.isNull()) |
| 2390 | return QualType(); |
| 2391 | |
| 2392 | // Array bounds are not potentially evaluated contexts |
| 2393 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2394 | |
| 2395 | Sema::OwningExprResult SizeResult |
| 2396 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2397 | if (SizeResult.isInvalid()) |
| 2398 | return QualType(); |
| 2399 | |
| 2400 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2401 | |
| 2402 | QualType Result = TL.getType(); |
| 2403 | if (getDerived().AlwaysRebuild() || |
| 2404 | ElementType != T->getElementType() || |
| 2405 | Size != T->getSizeExpr()) { |
| 2406 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2407 | T->getSizeModifier(), |
| 2408 | move(SizeResult), |
| 2409 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2410 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2411 | if (Result.isNull()) |
| 2412 | return QualType(); |
| 2413 | } |
| 2414 | else SizeResult.take(); |
| 2415 | |
| 2416 | // We might have any sort of array type now, but fortunately they |
| 2417 | // all have the same location layout. |
| 2418 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2419 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2420 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2421 | NewTL.setSizeExpr(Size); |
| 2422 | |
| 2423 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2425 | |
| 2426 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2427 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2428 | TypeLocBuilder &TLB, |
| 2429 | DependentSizedExtVectorTypeLoc TL) { |
| 2430 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2431 | |
| 2432 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2433 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2434 | if (ElementType.isNull()) |
| 2435 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2437 | // Vector sizes are not potentially evaluated contexts |
| 2438 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2439 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2440 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2441 | if (Size.isInvalid()) |
| 2442 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2444 | QualType Result = TL.getType(); |
| 2445 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2446 | ElementType != T->getElementType() || |
| 2447 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2448 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2449 | move(Size), |
| 2450 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2451 | if (Result.isNull()) |
| 2452 | return QualType(); |
| 2453 | } |
| 2454 | else Size.take(); |
| 2455 | |
| 2456 | // Result might be dependent or not. |
| 2457 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2458 | DependentSizedExtVectorTypeLoc NewTL |
| 2459 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2460 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2461 | } else { |
| 2462 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2463 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2464 | } |
| 2465 | |
| 2466 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2467 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2468 | |
| 2469 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2470 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2471 | VectorTypeLoc TL) { |
| 2472 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2473 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2474 | if (ElementType.isNull()) |
| 2475 | return QualType(); |
| 2476 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2477 | QualType Result = TL.getType(); |
| 2478 | if (getDerived().AlwaysRebuild() || |
| 2479 | ElementType != T->getElementType()) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2480 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2481 | T->isAltiVec(), T->isPixel()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2482 | if (Result.isNull()) |
| 2483 | return QualType(); |
| 2484 | } |
| 2485 | |
| 2486 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2487 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2488 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2489 | return Result; |
| 2490 | } |
| 2491 | |
| 2492 | template<typename Derived> |
| 2493 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2494 | ExtVectorTypeLoc TL) { |
| 2495 | VectorType *T = TL.getTypePtr(); |
| 2496 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2497 | if (ElementType.isNull()) |
| 2498 | return QualType(); |
| 2499 | |
| 2500 | QualType Result = TL.getType(); |
| 2501 | if (getDerived().AlwaysRebuild() || |
| 2502 | ElementType != T->getElementType()) { |
| 2503 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2504 | T->getNumElements(), |
| 2505 | /*FIXME*/ SourceLocation()); |
| 2506 | if (Result.isNull()) |
| 2507 | return QualType(); |
| 2508 | } |
| 2509 | |
| 2510 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2511 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2512 | |
| 2513 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2514 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2515 | |
| 2516 | template<typename Derived> |
| 2517 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2518 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2519 | FunctionProtoTypeLoc TL) { |
| 2520 | FunctionProtoType *T = TL.getTypePtr(); |
| 2521 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2522 | if (ResultType.isNull()) |
| 2523 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2524 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2525 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2526 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2527 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2528 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2529 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2530 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2531 | QualType NewType; |
| 2532 | ParmVarDecl *NewParm; |
| 2533 | |
| 2534 | if (OldParm) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2535 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2536 | assert(OldDI->getType() == T->getArgType(i)); |
| 2537 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2538 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2539 | if (!NewDI) |
| 2540 | return QualType(); |
| 2541 | |
| 2542 | if (NewDI == OldDI) |
| 2543 | NewParm = OldParm; |
| 2544 | else |
| 2545 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2546 | OldParm->getDeclContext(), |
| 2547 | OldParm->getLocation(), |
| 2548 | OldParm->getIdentifier(), |
| 2549 | NewDI->getType(), |
| 2550 | NewDI, |
| 2551 | OldParm->getStorageClass(), |
| 2552 | /* DefArg */ NULL); |
| 2553 | NewType = NewParm->getType(); |
| 2554 | |
| 2555 | // Deal with the possibility that we don't have a parameter |
| 2556 | // declaration for this parameter. |
| 2557 | } else { |
| 2558 | NewParm = 0; |
| 2559 | |
| 2560 | QualType OldType = T->getArgType(i); |
| 2561 | NewType = getDerived().TransformType(OldType); |
| 2562 | if (NewType.isNull()) |
| 2563 | return QualType(); |
| 2564 | } |
| 2565 | |
| 2566 | ParamTypes.push_back(NewType); |
| 2567 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2568 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2569 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2570 | QualType Result = TL.getType(); |
| 2571 | if (getDerived().AlwaysRebuild() || |
| 2572 | ResultType != T->getResultType() || |
| 2573 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2574 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2575 | ParamTypes.data(), |
| 2576 | ParamTypes.size(), |
| 2577 | T->isVariadic(), |
| 2578 | T->getTypeQuals()); |
| 2579 | if (Result.isNull()) |
| 2580 | return QualType(); |
| 2581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2582 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2583 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2584 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2585 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2586 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2587 | NewTL.setArg(i, ParamDecls[i]); |
| 2588 | |
| 2589 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2590 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2592 | template<typename Derived> |
| 2593 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2594 | TypeLocBuilder &TLB, |
| 2595 | FunctionNoProtoTypeLoc TL) { |
| 2596 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2597 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2598 | if (ResultType.isNull()) |
| 2599 | return QualType(); |
| 2600 | |
| 2601 | QualType Result = TL.getType(); |
| 2602 | if (getDerived().AlwaysRebuild() || |
| 2603 | ResultType != T->getResultType()) |
| 2604 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2605 | |
| 2606 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2607 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2608 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2609 | |
| 2610 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2611 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2612 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2613 | template<typename Derived> QualType |
| 2614 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2615 | UnresolvedUsingTypeLoc TL) { |
| 2616 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2617 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2618 | if (!D) |
| 2619 | return QualType(); |
| 2620 | |
| 2621 | QualType Result = TL.getType(); |
| 2622 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2623 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2624 | if (Result.isNull()) |
| 2625 | return QualType(); |
| 2626 | } |
| 2627 | |
| 2628 | // We might get an arbitrary type spec type back. We should at |
| 2629 | // least always get a type spec type, though. |
| 2630 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2631 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2632 | |
| 2633 | return Result; |
| 2634 | } |
| 2635 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2636 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2637 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2638 | TypedefTypeLoc TL) { |
| 2639 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2640 | TypedefDecl *Typedef |
| 2641 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2642 | if (!Typedef) |
| 2643 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2644 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2645 | QualType Result = TL.getType(); |
| 2646 | if (getDerived().AlwaysRebuild() || |
| 2647 | Typedef != T->getDecl()) { |
| 2648 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2649 | if (Result.isNull()) |
| 2650 | return QualType(); |
| 2651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2652 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2653 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2654 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2655 | |
| 2656 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2658 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2659 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2660 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2661 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2662 | // typeof expressions are not potentially evaluated contexts |
| 2663 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2664 | |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2665 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2666 | if (E.isInvalid()) |
| 2667 | return QualType(); |
| 2668 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2669 | QualType Result = TL.getType(); |
| 2670 | if (getDerived().AlwaysRebuild() || |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2671 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2672 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2673 | if (Result.isNull()) |
| 2674 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2675 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2676 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2677 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2678 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2679 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2680 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2681 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2682 | |
| 2683 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2685 | |
| 2686 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2687 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2688 | TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2689 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2690 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2691 | if (!New_Under_TI) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2692 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2693 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2694 | QualType Result = TL.getType(); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2695 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2696 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2697 | if (Result.isNull()) |
| 2698 | return QualType(); |
| 2699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2700 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2701 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2702 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2703 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2704 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2705 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2706 | |
| 2707 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2709 | |
| 2710 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2711 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2712 | DecltypeTypeLoc TL) { |
| 2713 | DecltypeType *T = TL.getTypePtr(); |
| 2714 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2715 | // decltype expressions are not potentially evaluated contexts |
| 2716 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2717 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2718 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2719 | if (E.isInvalid()) |
| 2720 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2721 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2722 | QualType Result = TL.getType(); |
| 2723 | if (getDerived().AlwaysRebuild() || |
| 2724 | E.get() != T->getUnderlyingExpr()) { |
| 2725 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2726 | if (Result.isNull()) |
| 2727 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2728 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2729 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2730 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2731 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2732 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2733 | |
| 2734 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2738 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2739 | RecordTypeLoc TL) { |
| 2740 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2741 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2742 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2743 | if (!Record) |
| 2744 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2745 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2746 | QualType Result = TL.getType(); |
| 2747 | if (getDerived().AlwaysRebuild() || |
| 2748 | Record != T->getDecl()) { |
| 2749 | Result = getDerived().RebuildRecordType(Record); |
| 2750 | if (Result.isNull()) |
| 2751 | return QualType(); |
| 2752 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2753 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2755 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2756 | |
| 2757 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2758 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2759 | |
| 2760 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2762 | EnumTypeLoc TL) { |
| 2763 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2764 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2765 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2766 | if (!Enum) |
| 2767 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2768 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2769 | QualType Result = TL.getType(); |
| 2770 | if (getDerived().AlwaysRebuild() || |
| 2771 | Enum != T->getDecl()) { |
| 2772 | Result = getDerived().RebuildEnumType(Enum); |
| 2773 | if (Result.isNull()) |
| 2774 | return QualType(); |
| 2775 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2777 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2778 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2779 | |
| 2780 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2781 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2782 | |
| 2783 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2784 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2785 | ElaboratedTypeLoc TL) { |
| 2786 | ElaboratedType *T = TL.getTypePtr(); |
| 2787 | |
| 2788 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2789 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2790 | if (Underlying.isNull()) |
| 2791 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2793 | QualType Result = TL.getType(); |
| 2794 | if (getDerived().AlwaysRebuild() || |
| 2795 | Underlying != T->getUnderlyingType()) { |
| 2796 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2797 | if (Result.isNull()) |
| 2798 | return QualType(); |
| 2799 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2800 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2801 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2802 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2803 | |
| 2804 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2806 | |
| 2807 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2808 | template<typename Derived> |
| 2809 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2810 | TypeLocBuilder &TLB, |
| 2811 | TemplateTypeParmTypeLoc TL) { |
| 2812 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2815 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2816 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2817 | TypeLocBuilder &TLB, |
| 2818 | SubstTemplateTypeParmTypeLoc TL) { |
| 2819 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2823 | inline QualType |
| 2824 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2825 | TypeLocBuilder &TLB, |
| 2826 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2827 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2828 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2830 | template<typename Derived> |
| 2831 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2832 | const TemplateSpecializationType *TST, |
| 2833 | QualType ObjectType) { |
| 2834 | // FIXME: this entire method is a temporary workaround; callers |
| 2835 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2836 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2837 | // Fake up a TemplateSpecializationTypeLoc. |
| 2838 | TypeLocBuilder TLB; |
| 2839 | TemplateSpecializationTypeLoc TL |
| 2840 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2841 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2842 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2843 | |
| 2844 | TL.setTemplateNameLoc(BaseLoc); |
| 2845 | TL.setLAngleLoc(BaseLoc); |
| 2846 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2847 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2848 | const TemplateArgument &TA = TST->getArg(i); |
| 2849 | TemplateArgumentLoc TAL; |
| 2850 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2851 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2852 | } |
| 2853 | |
| 2854 | TypeLocBuilder IgnoredTLB; |
| 2855 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2859 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2860 | TypeLocBuilder &TLB, |
| 2861 | TemplateSpecializationTypeLoc TL, |
| 2862 | QualType ObjectType) { |
| 2863 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2864 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2865 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2866 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2867 | if (Template.isNull()) |
| 2868 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2869 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2870 | TemplateArgumentListInfo NewTemplateArgs; |
| 2871 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2872 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2873 | |
| 2874 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2875 | TemplateArgumentLoc Loc; |
| 2876 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2877 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2878 | NewTemplateArgs.addArgument(Loc); |
| 2879 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2880 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2881 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2882 | |
| 2883 | QualType Result = |
| 2884 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2885 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2886 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2887 | |
| 2888 | if (!Result.isNull()) { |
| 2889 | TemplateSpecializationTypeLoc NewTL |
| 2890 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2891 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2892 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2893 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2894 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2895 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2896 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2897 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2898 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2899 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2900 | |
| 2901 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2902 | QualType |
| 2903 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2904 | QualifiedNameTypeLoc TL) { |
| 2905 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2906 | NestedNameSpecifier *NNS |
| 2907 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2908 | SourceRange()); |
| 2909 | if (!NNS) |
| 2910 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2911 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2912 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2913 | if (Named.isNull()) |
| 2914 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2915 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2916 | QualType Result = TL.getType(); |
| 2917 | if (getDerived().AlwaysRebuild() || |
| 2918 | NNS != T->getQualifier() || |
| 2919 | Named != T->getNamedType()) { |
| 2920 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2921 | if (Result.isNull()) |
| 2922 | return QualType(); |
| 2923 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2924 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2925 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2926 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2927 | |
| 2928 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2930 | |
| 2931 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2933 | TypenameTypeLoc TL) { |
| 2934 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2935 | |
| 2936 | /* FIXME: preserve source information better than this */ |
| 2937 | SourceRange SR(TL.getNameLoc()); |
| 2938 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2939 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2940 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2941 | if (!NNS) |
| 2942 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2944 | QualType Result; |
| 2945 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2946 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2947 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2948 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2949 | if (NewTemplateId.isNull()) |
| 2950 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2951 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2952 | if (!getDerived().AlwaysRebuild() && |
| 2953 | NNS == T->getQualifier() && |
| 2954 | NewTemplateId == QualType(TemplateId, 0)) |
| 2955 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2956 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2957 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2958 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2959 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2960 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2961 | if (Result.isNull()) |
| 2962 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2963 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2964 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2965 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2966 | |
| 2967 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2968 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2970 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2971 | QualType |
| 2972 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2973 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2974 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2975 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2976 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2977 | |
| 2978 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2979 | QualType |
| 2980 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2981 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2982 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2983 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2986 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2987 | // Statement transformation |
| 2988 | //===----------------------------------------------------------------------===// |
| 2989 | template<typename Derived> |
| 2990 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2991 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2992 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | template<typename Derived> |
| 2996 | Sema::OwningStmtResult |
| 2997 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2998 | return getDerived().TransformCompoundStmt(S, false); |
| 2999 | } |
| 3000 | |
| 3001 | template<typename Derived> |
| 3002 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3003 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3004 | bool IsStmtExpr) { |
| 3005 | bool SubStmtChanged = false; |
| 3006 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3007 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3008 | B != BEnd; ++B) { |
| 3009 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3010 | if (Result.isInvalid()) |
| 3011 | return getSema().StmtError(); |
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 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3014 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3015 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3016 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3017 | if (!getDerived().AlwaysRebuild() && |
| 3018 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3019 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3020 | |
| 3021 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3022 | move_arg(Statements), |
| 3023 | S->getRBracLoc(), |
| 3024 | IsStmtExpr); |
| 3025 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3027 | template<typename Derived> |
| 3028 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3029 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3030 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3031 | { |
| 3032 | // The case value expressions are not potentially evaluated. |
| 3033 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3035 | // Transform the left-hand case value. |
| 3036 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3037 | if (LHS.isInvalid()) |
| 3038 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3040 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3041 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3042 | if (RHS.isInvalid()) |
| 3043 | return SemaRef.StmtError(); |
| 3044 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3046 | // Build the case statement. |
| 3047 | // Case statements are always rebuilt so that they will attached to their |
| 3048 | // transformed switch statement. |
| 3049 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3050 | move(LHS), |
| 3051 | S->getEllipsisLoc(), |
| 3052 | move(RHS), |
| 3053 | S->getColonLoc()); |
| 3054 | if (Case.isInvalid()) |
| 3055 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3056 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3057 | // Transform the statement following the case |
| 3058 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3059 | if (SubStmt.isInvalid()) |
| 3060 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3062 | // Attach the body to the case statement |
| 3063 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3064 | } |
| 3065 | |
| 3066 | template<typename Derived> |
| 3067 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3068 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3069 | // Transform the statement following the default case |
| 3070 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3071 | if (SubStmt.isInvalid()) |
| 3072 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3073 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3074 | // Default statements are always rebuilt |
| 3075 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3076 | move(SubStmt)); |
| 3077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3079 | template<typename Derived> |
| 3080 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3082 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3083 | if (SubStmt.isInvalid()) |
| 3084 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3085 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3086 | // FIXME: Pass the real colon location in. |
| 3087 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3088 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3089 | move(SubStmt)); |
| 3090 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3091 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3092 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | Sema::OwningStmtResult |
| 3094 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3095 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3096 | OwningExprResult Cond(SemaRef); |
| 3097 | VarDecl *ConditionVar = 0; |
| 3098 | if (S->getConditionVariable()) { |
| 3099 | ConditionVar |
| 3100 | = cast_or_null<VarDecl>( |
| 3101 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3102 | if (!ConditionVar) |
| 3103 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3104 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3105 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3106 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3107 | if (Cond.isInvalid()) |
| 3108 | return SemaRef.StmtError(); |
| 3109 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3110 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3111 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3112 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3113 | // Transform the "then" branch. |
| 3114 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3115 | if (Then.isInvalid()) |
| 3116 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3117 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3118 | // Transform the "else" branch. |
| 3119 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3120 | if (Else.isInvalid()) |
| 3121 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3122 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3123 | if (!getDerived().AlwaysRebuild() && |
| 3124 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3125 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3126 | Then.get() == S->getThen() && |
| 3127 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | return SemaRef.Owned(S->Retain()); |
| 3129 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3130 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3131 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | template<typename Derived> |
| 3136 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3138 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3139 | OwningExprResult Cond(SemaRef); |
| 3140 | VarDecl *ConditionVar = 0; |
| 3141 | if (S->getConditionVariable()) { |
| 3142 | ConditionVar |
| 3143 | = cast_or_null<VarDecl>( |
| 3144 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3145 | if (!ConditionVar) |
| 3146 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3147 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3148 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3149 | |
| 3150 | if (Cond.isInvalid()) |
| 3151 | return SemaRef.StmtError(); |
| 3152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3153 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3154 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3155 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3156 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3157 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3158 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | if (Switch.isInvalid()) |
| 3160 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3162 | // Transform the body of the switch statement. |
| 3163 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3164 | if (Body.isInvalid()) |
| 3165 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | // Complete the switch statement. |
| 3168 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3169 | move(Body)); |
| 3170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3171 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3172 | template<typename Derived> |
| 3173 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3175 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3176 | OwningExprResult Cond(SemaRef); |
| 3177 | VarDecl *ConditionVar = 0; |
| 3178 | if (S->getConditionVariable()) { |
| 3179 | ConditionVar |
| 3180 | = cast_or_null<VarDecl>( |
| 3181 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3182 | if (!ConditionVar) |
| 3183 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3184 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3185 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3186 | |
| 3187 | if (Cond.isInvalid()) |
| 3188 | return SemaRef.StmtError(); |
| 3189 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3191 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3192 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3193 | // Transform the body |
| 3194 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3195 | if (Body.isInvalid()) |
| 3196 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3198 | if (!getDerived().AlwaysRebuild() && |
| 3199 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3200 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3201 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | return SemaRef.Owned(S->Retain()); |
| 3203 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3204 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3205 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3206 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3207 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3208 | template<typename Derived> |
| 3209 | Sema::OwningStmtResult |
| 3210 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3211 | // Transform the condition |
| 3212 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3213 | if (Cond.isInvalid()) |
| 3214 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3215 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3216 | // Transform the body |
| 3217 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3218 | if (Body.isInvalid()) |
| 3219 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | if (!getDerived().AlwaysRebuild() && |
| 3222 | Cond.get() == S->getCond() && |
| 3223 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3224 | return SemaRef.Owned(S->Retain()); |
| 3225 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3227 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3228 | S->getRParenLoc()); |
| 3229 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | template<typename Derived> |
| 3232 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3234 | // Transform the initialization statement |
| 3235 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3236 | if (Init.isInvalid()) |
| 3237 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3239 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3240 | OwningExprResult Cond(SemaRef); |
| 3241 | VarDecl *ConditionVar = 0; |
| 3242 | if (S->getConditionVariable()) { |
| 3243 | ConditionVar |
| 3244 | = cast_or_null<VarDecl>( |
| 3245 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3246 | if (!ConditionVar) |
| 3247 | return SemaRef.StmtError(); |
| 3248 | } else { |
| 3249 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3250 | |
| 3251 | if (Cond.isInvalid()) |
| 3252 | return SemaRef.StmtError(); |
| 3253 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3255 | // Transform the increment |
| 3256 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3257 | if (Inc.isInvalid()) |
| 3258 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3260 | // Transform the body |
| 3261 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3262 | if (Body.isInvalid()) |
| 3263 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3264 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3265 | if (!getDerived().AlwaysRebuild() && |
| 3266 | Init.get() == S->getInit() && |
| 3267 | Cond.get() == S->getCond() && |
| 3268 | Inc.get() == S->getInc() && |
| 3269 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | return SemaRef.Owned(S->Retain()); |
| 3271 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3272 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3273 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3274 | ConditionVar, |
Anders Carlsson | 5ee56e9 | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3275 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | S->getRParenLoc(), move(Body)); |
| 3277 | } |
| 3278 | |
| 3279 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3280 | Sema::OwningStmtResult |
| 3281 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3283 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | S->getLabel()); |
| 3285 | } |
| 3286 | |
| 3287 | template<typename Derived> |
| 3288 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3289 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3290 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3291 | if (Target.isInvalid()) |
| 3292 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3293 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3294 | if (!getDerived().AlwaysRebuild() && |
| 3295 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3296 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3297 | |
| 3298 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3299 | move(Target)); |
| 3300 | } |
| 3301 | |
| 3302 | template<typename Derived> |
| 3303 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3304 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3305 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3308 | template<typename Derived> |
| 3309 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3311 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | template<typename Derived> |
| 3315 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3318 | if (Result.isInvalid()) |
| 3319 | return SemaRef.StmtError(); |
| 3320 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3322 | // to tell whether the return type of the function has changed. |
| 3323 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3325 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3326 | template<typename Derived> |
| 3327 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3329 | bool DeclChanged = false; |
| 3330 | llvm::SmallVector<Decl *, 4> Decls; |
| 3331 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3332 | D != DEnd; ++D) { |
| 3333 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3334 | if (!Transformed) |
| 3335 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | if (Transformed != *D) |
| 3338 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3339 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3340 | Decls.push_back(Transformed); |
| 3341 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | return SemaRef.Owned(S->Retain()); |
| 3345 | |
| 3346 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3347 | S->getStartLoc(), S->getEndLoc()); |
| 3348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3349 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | template<typename Derived> |
| 3351 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3354 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | template<typename Derived> |
| 3358 | Sema::OwningStmtResult |
| 3359 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3360 | |
| 3361 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3362 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3363 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3364 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3365 | OwningExprResult AsmString(SemaRef); |
| 3366 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3367 | |
| 3368 | bool ExprsChanged = false; |
| 3369 | |
| 3370 | // Go through the outputs. |
| 3371 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3372 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3373 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3374 | // No need to transform the constraint literal. |
| 3375 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3376 | |
| 3377 | // Transform the output expr. |
| 3378 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3379 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3380 | if (Result.isInvalid()) |
| 3381 | return SemaRef.StmtError(); |
| 3382 | |
| 3383 | ExprsChanged |= Result.get() != OutputExpr; |
| 3384 | |
| 3385 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3386 | } |
| 3387 | |
| 3388 | // Go through the inputs. |
| 3389 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | ff93dbd | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3390 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3391 | |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3392 | // No need to transform the constraint literal. |
| 3393 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3394 | |
| 3395 | // Transform the input expr. |
| 3396 | Expr *InputExpr = S->getInputExpr(I); |
| 3397 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3398 | if (Result.isInvalid()) |
| 3399 | return SemaRef.StmtError(); |
| 3400 | |
| 3401 | ExprsChanged |= Result.get() != InputExpr; |
| 3402 | |
| 3403 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3404 | } |
| 3405 | |
| 3406 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3407 | return SemaRef.Owned(S->Retain()); |
| 3408 | |
| 3409 | // Go through the clobbers. |
| 3410 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3411 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3412 | |
| 3413 | // No need to transform the asm string literal. |
| 3414 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3415 | |
| 3416 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3417 | S->isSimple(), |
| 3418 | S->isVolatile(), |
| 3419 | S->getNumOutputs(), |
| 3420 | S->getNumInputs(), |
Anders Carlsson | a5a79f7 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3421 | Names.data(), |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3422 | move_arg(Constraints), |
| 3423 | move_arg(Exprs), |
| 3424 | move(AsmString), |
| 3425 | move_arg(Clobbers), |
| 3426 | S->getRParenLoc(), |
| 3427 | S->isMSAsm()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | |
| 3431 | template<typename Derived> |
| 3432 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3433 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | // FIXME: Implement this |
| 3435 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3436 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3437 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3439 | template<typename Derived> |
| 3440 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | // FIXME: Implement this |
| 3443 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3444 | return SemaRef.Owned(S->Retain()); |
| 3445 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | template<typename Derived> |
| 3448 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | // FIXME: Implement this |
| 3451 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3453 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | template<typename Derived> |
| 3456 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3458 | // FIXME: Implement this |
| 3459 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3460 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3461 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3463 | template<typename Derived> |
| 3464 | Sema::OwningStmtResult |
| 3465 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3466 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3467 | // FIXME: Implement this |
| 3468 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | template<typename Derived> |
| 3473 | Sema::OwningStmtResult |
| 3474 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3475 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3476 | // FIXME: Implement this |
| 3477 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3478 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | |
| 3482 | template<typename Derived> |
| 3483 | Sema::OwningStmtResult |
| 3484 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3485 | // Transform the exception declaration, if any. |
| 3486 | VarDecl *Var = 0; |
| 3487 | if (S->getExceptionDecl()) { |
| 3488 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3489 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3490 | ExceptionDecl->getDeclName()); |
| 3491 | |
| 3492 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3493 | if (T.isNull()) |
| 3494 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3495 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3496 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3497 | T, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3498 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3499 | ExceptionDecl->getIdentifier(), |
| 3500 | ExceptionDecl->getLocation(), |
| 3501 | /*FIXME: Inaccurate*/ |
| 3502 | SourceRange(ExceptionDecl->getLocation())); |
| 3503 | if (!Var || Var->isInvalidDecl()) { |
| 3504 | if (Var) |
| 3505 | Var->Destroy(SemaRef.Context); |
| 3506 | return SemaRef.StmtError(); |
| 3507 | } |
| 3508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3509 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3510 | // Transform the actual exception handler. |
| 3511 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3512 | if (Handler.isInvalid()) { |
| 3513 | if (Var) |
| 3514 | Var->Destroy(SemaRef.Context); |
| 3515 | return SemaRef.StmtError(); |
| 3516 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3518 | if (!getDerived().AlwaysRebuild() && |
| 3519 | !Var && |
| 3520 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3522 | |
| 3523 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3524 | Var, |
| 3525 | move(Handler)); |
| 3526 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3528 | template<typename Derived> |
| 3529 | Sema::OwningStmtResult |
| 3530 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3531 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3533 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3534 | if (TryBlock.isInvalid()) |
| 3535 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3537 | // Transform the handlers. |
| 3538 | bool HandlerChanged = false; |
| 3539 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3540 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3543 | if (Handler.isInvalid()) |
| 3544 | return SemaRef.StmtError(); |
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 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3547 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3548 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3550 | if (!getDerived().AlwaysRebuild() && |
| 3551 | TryBlock.get() == S->getTryBlock() && |
| 3552 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3554 | |
| 3555 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3556 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3559 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3560 | // Expression transformation |
| 3561 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3562 | template<typename Derived> |
| 3563 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3564 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3566 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3567 | |
| 3568 | template<typename Derived> |
| 3569 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3570 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3571 | NestedNameSpecifier *Qualifier = 0; |
| 3572 | if (E->getQualifier()) { |
| 3573 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3574 | E->getQualifierRange()); |
| 3575 | if (!Qualifier) |
| 3576 | return SemaRef.ExprError(); |
| 3577 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3578 | |
| 3579 | ValueDecl *ND |
| 3580 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3581 | if (!ND) |
| 3582 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3584 | if (!getDerived().AlwaysRebuild() && |
| 3585 | Qualifier == E->getQualifier() && |
| 3586 | ND == E->getDecl() && |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3587 | !E->hasExplicitTemplateArgumentList()) { |
| 3588 | |
| 3589 | // Mark it referenced in the new context regardless. |
| 3590 | // FIXME: this is a bit instantiation-specific. |
| 3591 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3592 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3593 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3594 | } |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3595 | |
| 3596 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3597 | if (E->hasExplicitTemplateArgumentList()) { |
| 3598 | TemplateArgs = &TransArgs; |
| 3599 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3600 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3601 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3602 | TemplateArgumentLoc Loc; |
| 3603 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3604 | return SemaRef.ExprError(); |
| 3605 | TransArgs.addArgument(Loc); |
| 3606 | } |
| 3607 | } |
| 3608 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3609 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | dbd872f | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3610 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3611 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3613 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3615 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3617 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3619 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3621 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3624 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3625 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3626 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3627 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3630 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3631 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3633 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3634 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3635 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3636 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3637 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3638 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3639 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 | return SemaRef.Owned(E->Retain()); |
| 3641 | } |
| 3642 | |
| 3643 | template<typename Derived> |
| 3644 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3645 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3647 | if (SubExpr.isInvalid()) |
| 3648 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3650 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | return SemaRef.Owned(E->Retain()); |
| 3652 | |
| 3653 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3654 | E->getRParen()); |
| 3655 | } |
| 3656 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | template<typename Derived> |
| 3658 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3659 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3660 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3661 | if (SubExpr.isInvalid()) |
| 3662 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3664 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | return SemaRef.Owned(E->Retain()); |
| 3666 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3667 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3668 | E->getOpcode(), |
| 3669 | move(SubExpr)); |
| 3670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3671 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3672 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3673 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3674 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | if (E->isArgumentType()) { |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3676 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3677 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3678 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3679 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3680 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3681 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3682 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3683 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3685 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3687 | E->getSourceRange()); |
| 3688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3690 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3691 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3692 | // C++0x [expr.sizeof]p1: |
| 3693 | // The operand is either an expression, which is an unevaluated operand |
| 3694 | // [...] |
| 3695 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
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 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3698 | if (SubExpr.isInvalid()) |
| 3699 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3702 | return SemaRef.Owned(E->Retain()); |
| 3703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3705 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3706 | E->isSizeOf(), |
| 3707 | E->getSourceRange()); |
| 3708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3710 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3712 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3713 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3714 | if (LHS.isInvalid()) |
| 3715 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3716 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3717 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3718 | if (RHS.isInvalid()) |
| 3719 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3720 | |
| 3721 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | if (!getDerived().AlwaysRebuild() && |
| 3723 | LHS.get() == E->getLHS() && |
| 3724 | RHS.get() == E->getRHS()) |
| 3725 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3728 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3729 | move(RHS), |
| 3730 | E->getRBracketLoc()); |
| 3731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3732 | |
| 3733 | template<typename Derived> |
| 3734 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3735 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3736 | // Transform the callee. |
| 3737 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3738 | if (Callee.isInvalid()) |
| 3739 | return SemaRef.ExprError(); |
| 3740 | |
| 3741 | // Transform arguments. |
| 3742 | bool ArgChanged = false; |
| 3743 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3744 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3745 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3746 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3747 | if (Arg.isInvalid()) |
| 3748 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3750 | // FIXME: Wrong source location information for the ','. |
| 3751 | FakeCommaLocs.push_back( |
| 3752 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
| 3754 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3755 | Args.push_back(Arg.takeAs<Expr>()); |
| 3756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3757 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3758 | if (!getDerived().AlwaysRebuild() && |
| 3759 | Callee.get() == E->getCallee() && |
| 3760 | !ArgChanged) |
| 3761 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3762 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3763 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3765 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3766 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3767 | move_arg(Args), |
| 3768 | FakeCommaLocs.data(), |
| 3769 | E->getRParenLoc()); |
| 3770 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3771 | |
| 3772 | template<typename Derived> |
| 3773 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3774 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3775 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3776 | if (Base.isInvalid()) |
| 3777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3779 | NestedNameSpecifier *Qualifier = 0; |
| 3780 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3781 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3782 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3783 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3784 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3785 | return SemaRef.ExprError(); |
| 3786 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Eli Friedman | f595cc4 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3788 | ValueDecl *Member |
| 3789 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3790 | if (!Member) |
| 3791 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3793 | if (!getDerived().AlwaysRebuild() && |
| 3794 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3795 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3796 | Member == E->getMemberDecl() && |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3797 | !E->hasExplicitTemplateArgumentList()) { |
| 3798 | |
| 3799 | // Mark it referenced in the new context regardless. |
| 3800 | // FIXME: this is a bit instantiation-specific. |
| 3801 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3802 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 1f24032 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3803 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3804 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3805 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3806 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3807 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3808 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3809 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3810 | TemplateArgumentLoc Loc; |
| 3811 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3812 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3813 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3817 | // FIXME: Bogus source location for the operator |
| 3818 | SourceLocation FakeOperatorLoc |
| 3819 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3820 | |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3821 | // FIXME: to do this check properly, we will need to preserve the |
| 3822 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3823 | // base (and therefore couldn't do the check) and a |
| 3824 | // nested-name-qualifier (and therefore could do the lookup). |
| 3825 | NamedDecl *FirstQualifierInScope = 0; |
| 3826 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3827 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3828 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3829 | Qualifier, |
| 3830 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3831 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3832 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3833 | (E->hasExplicitTemplateArgumentList() |
| 3834 | ? &TransArgs : 0), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3835 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3836 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3838 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3839 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3840 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3841 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3842 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3846 | if (RHS.isInvalid()) |
| 3847 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | if (!getDerived().AlwaysRebuild() && |
| 3850 | LHS.get() == E->getLHS() && |
| 3851 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | return SemaRef.Owned(E->Retain()); |
| 3853 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3855 | move(LHS), move(RHS)); |
| 3856 | } |
| 3857 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | Sema::OwningExprResult |
| 3860 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3861 | CompoundAssignOperator *E) { |
| 3862 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3863 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3864 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3865 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3867 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3869 | if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS()); |
| 3873 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3877 | if (RHS.isInvalid()) |
| 3878 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3880 | if (!getDerived().AlwaysRebuild() && |
| 3881 | Cond.get() == E->getCond() && |
| 3882 | LHS.get() == E->getLHS() && |
| 3883 | RHS.get() == E->getRHS()) |
| 3884 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3885 | |
| 3886 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3887 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3889 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3890 | move(RHS)); |
| 3891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3892 | |
| 3893 | template<typename Derived> |
| 3894 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3895 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3896 | // Implicit casts are eliminated during transformation, since they |
| 3897 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3898 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3899 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3900 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3901 | template<typename Derived> |
| 3902 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3903 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3904 | TypeSourceInfo *OldT; |
| 3905 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | { |
| 3907 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3908 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3909 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3910 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3912 | OldT = E->getTypeInfoAsWritten(); |
| 3913 | NewT = getDerived().TransformType(OldT); |
| 3914 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | return SemaRef.ExprError(); |
| 3916 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3918 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3919 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | if (SubExpr.isInvalid()) |
| 3921 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3923 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3924 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | return SemaRef.Owned(E->Retain()); |
| 3927 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3928 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3929 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | E->getRParenLoc(), |
| 3931 | move(SubExpr)); |
| 3932 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3936 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3937 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3938 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3939 | if (!NewT) |
| 3940 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3941 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3942 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3943 | if (Init.isInvalid()) |
| 3944 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3946 | if (!getDerived().AlwaysRebuild() && |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3947 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | |
John McCall | 1d7d8d6 | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3951 | // Note: the expression type doesn't necessarily match the |
| 3952 | // type-as-written, but that's okay, because it should always be |
| 3953 | // derivable from the initializer. |
| 3954 | |
John McCall | 42f56b5 | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3955 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3957 | move(Init)); |
| 3958 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3959 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3960 | template<typename Derived> |
| 3961 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3962 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3964 | if (Base.isInvalid()) |
| 3965 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3967 | if (!getDerived().AlwaysRebuild() && |
| 3968 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3969 | return SemaRef.Owned(E->Retain()); |
| 3970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3971 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3974 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3975 | E->getAccessorLoc(), |
| 3976 | E->getAccessor()); |
| 3977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3979 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3981 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3982 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3984 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3985 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3986 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3987 | if (Init.isInvalid()) |
| 3988 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3989 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3990 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3991 | Inits.push_back(Init.takeAs<Expr>()); |
| 3992 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3994 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3995 | return SemaRef.Owned(E->Retain()); |
| 3996 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3997 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3998 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
| 4002 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4003 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4004 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4006 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4007 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4008 | if (Init.isInvalid()) |
| 4009 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4010 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4011 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4013 | bool ExprChanged = false; |
| 4014 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4015 | DEnd = E->designators_end(); |
| 4016 | D != DEnd; ++D) { |
| 4017 | if (D->isFieldDesignator()) { |
| 4018 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4019 | D->getDotLoc(), |
| 4020 | D->getFieldLoc())); |
| 4021 | continue; |
| 4022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | if (D->isArrayDesignator()) { |
| 4025 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4026 | if (Index.isInvalid()) |
| 4027 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
| 4029 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4030 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4032 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4033 | ArrayExprs.push_back(Index.release()); |
| 4034 | continue; |
| 4035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4037 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4038 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4039 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4040 | if (Start.isInvalid()) |
| 4041 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4042 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4043 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4044 | if (End.isInvalid()) |
| 4045 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
| 4047 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | End.get(), |
| 4049 | D->getLBracketLoc(), |
| 4050 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4052 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4053 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4055 | ArrayExprs.push_back(Start.release()); |
| 4056 | ArrayExprs.push_back(End.release()); |
| 4057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4059 | if (!getDerived().AlwaysRebuild() && |
| 4060 | Init.get() == E->getInit() && |
| 4061 | !ExprChanged) |
| 4062 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4065 | E->getEqualOrColonLoc(), |
| 4066 | E->usesGNUSyntax(), move(Init)); |
| 4067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4070 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4071 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4072 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4073 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4074 | |
| 4075 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4076 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | QualType T = getDerived().TransformType(E->getType()); |
| 4078 | if (T.isNull()) |
| 4079 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4081 | if (!getDerived().AlwaysRebuild() && |
| 4082 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | return SemaRef.Owned(E->Retain()); |
| 4084 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4085 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4090 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | // FIXME: Do we want the type as written? |
| 4092 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4094 | { |
| 4095 | // FIXME: Source location isn't quite accurate. |
| 4096 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4097 | T = getDerived().TransformType(E->getType()); |
| 4098 | if (T.isNull()) |
| 4099 | return SemaRef.ExprError(); |
| 4100 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4101 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4102 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4103 | if (SubExpr.isInvalid()) |
| 4104 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4106 | if (!getDerived().AlwaysRebuild() && |
| 4107 | T == E->getType() && |
| 4108 | SubExpr.get() == E->getSubExpr()) |
| 4109 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4111 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4112 | T, E->getRParenLoc()); |
| 4113 | } |
| 4114 | |
| 4115 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4117 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | bool ArgumentChanged = false; |
| 4119 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4120 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4121 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4122 | if (Init.isInvalid()) |
| 4123 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4124 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4125 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4126 | Inits.push_back(Init.takeAs<Expr>()); |
| 4127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4128 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4129 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4130 | move_arg(Inits), |
| 4131 | E->getRParenLoc()); |
| 4132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4134 | /// \brief Transform an address-of-label expression. |
| 4135 | /// |
| 4136 | /// By default, the transformation of an address-of-label expression always |
| 4137 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4138 | /// the corresponding label statement by semantic analysis. |
| 4139 | template<typename Derived> |
| 4140 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4141 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4142 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4143 | E->getLabel()); |
| 4144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
| 4146 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4147 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4148 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4151 | if (SubStmt.isInvalid()) |
| 4152 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | if (!getDerived().AlwaysRebuild() && |
| 4155 | SubStmt.get() == E->getSubStmt()) |
| 4156 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | |
| 4158 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | move(SubStmt), |
| 4160 | E->getRParenLoc()); |
| 4161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4163 | template<typename Derived> |
| 4164 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4165 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4166 | QualType T1, T2; |
| 4167 | { |
| 4168 | // FIXME: Source location isn't quite accurate. |
| 4169 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4172 | if (T1.isNull()) |
| 4173 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4175 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4176 | if (T2.isNull()) |
| 4177 | return SemaRef.ExprError(); |
| 4178 | } |
| 4179 | |
| 4180 | if (!getDerived().AlwaysRebuild() && |
| 4181 | T1 == E->getArgType1() && |
| 4182 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | return SemaRef.Owned(E->Retain()); |
| 4184 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4186 | T1, T2, E->getRParenLoc()); |
| 4187 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4188 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4189 | template<typename Derived> |
| 4190 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4191 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4193 | if (Cond.isInvalid()) |
| 4194 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4197 | if (LHS.isInvalid()) |
| 4198 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4201 | if (RHS.isInvalid()) |
| 4202 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4204 | if (!getDerived().AlwaysRebuild() && |
| 4205 | Cond.get() == E->getCond() && |
| 4206 | LHS.get() == E->getLHS() && |
| 4207 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | return SemaRef.Owned(E->Retain()); |
| 4209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4211 | move(Cond), move(LHS), move(RHS), |
| 4212 | E->getRParenLoc()); |
| 4213 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4217 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | template<typename Derived> |
| 4222 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4223 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4224 | switch (E->getOperator()) { |
| 4225 | case OO_New: |
| 4226 | case OO_Delete: |
| 4227 | case OO_Array_New: |
| 4228 | case OO_Array_Delete: |
| 4229 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4230 | return SemaRef.ExprError(); |
| 4231 | |
| 4232 | case OO_Call: { |
| 4233 | // This is a call to an object's operator(). |
| 4234 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4235 | |
| 4236 | // Transform the object itself. |
| 4237 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4238 | if (Object.isInvalid()) |
| 4239 | return SemaRef.ExprError(); |
| 4240 | |
| 4241 | // FIXME: Poor location information |
| 4242 | SourceLocation FakeLParenLoc |
| 4243 | = SemaRef.PP.getLocForEndOfToken( |
| 4244 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4245 | |
| 4246 | // Transform the call arguments. |
| 4247 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4248 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4249 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4250 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4251 | break; |
| 4252 | |
Douglas Gregor | 668d6d9 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4253 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4254 | if (Arg.isInvalid()) |
| 4255 | return SemaRef.ExprError(); |
| 4256 | |
| 4257 | // FIXME: Poor source location information. |
| 4258 | SourceLocation FakeCommaLoc |
| 4259 | = SemaRef.PP.getLocForEndOfToken( |
| 4260 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4261 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4262 | Args.push_back(Arg.release()); |
| 4263 | } |
| 4264 | |
| 4265 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4266 | move_arg(Args), |
| 4267 | FakeCommaLocs.data(), |
| 4268 | E->getLocEnd()); |
| 4269 | } |
| 4270 | |
| 4271 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4272 | case OO_##Name: |
| 4273 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4274 | #include "clang/Basic/OperatorKinds.def" |
| 4275 | case OO_Subscript: |
| 4276 | // Handled below. |
| 4277 | break; |
| 4278 | |
| 4279 | case OO_Conditional: |
| 4280 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4281 | return SemaRef.ExprError(); |
| 4282 | |
| 4283 | case OO_None: |
| 4284 | case NUM_OVERLOADED_OPERATORS: |
| 4285 | llvm_unreachable("not an overloaded operator?"); |
| 4286 | return SemaRef.ExprError(); |
| 4287 | } |
| 4288 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4290 | if (Callee.isInvalid()) |
| 4291 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4292 | |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4293 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4294 | if (First.isInvalid()) |
| 4295 | return SemaRef.ExprError(); |
| 4296 | |
| 4297 | OwningExprResult Second(SemaRef); |
| 4298 | if (E->getNumArgs() == 2) { |
| 4299 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4300 | if (Second.isInvalid()) |
| 4301 | return SemaRef.ExprError(); |
| 4302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | if (!getDerived().AlwaysRebuild() && |
| 4305 | Callee.get() == E->getCallee() && |
| 4306 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4308 | return SemaRef.Owned(E->Retain()); |
| 4309 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4311 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | move(First), |
| 4314 | move(Second)); |
| 4315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4317 | template<typename Derived> |
| 4318 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4319 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4320 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4322 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4323 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4325 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4326 | TypeSourceInfo *OldT; |
| 4327 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | { |
| 4329 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4332 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4333 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4334 | OldT = E->getTypeInfoAsWritten(); |
| 4335 | NewT = getDerived().TransformType(OldT); |
| 4336 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | return SemaRef.ExprError(); |
| 4338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4340 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4341 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4342 | if (SubExpr.isInvalid()) |
| 4343 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4345 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4346 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4347 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | return SemaRef.Owned(E->Retain()); |
| 4349 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4352 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4353 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4354 | SourceLocation FakeRParenLoc |
| 4355 | = SemaRef.PP.getLocForEndOfToken( |
| 4356 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4357 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | FakeLAngleLoc, |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4360 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4361 | FakeRAngleLoc, |
| 4362 | FakeRAngleLoc, |
| 4363 | move(SubExpr), |
| 4364 | FakeRParenLoc); |
| 4365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | template<typename Derived> |
| 4368 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4369 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4370 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
| 4373 | template<typename Derived> |
| 4374 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4375 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4376 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | template<typename Derived> |
| 4380 | Sema::OwningExprResult |
| 4381 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4382 | CXXReinterpretCastExpr *E) { |
| 4383 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | template<typename Derived> |
| 4387 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4388 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4389 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | template<typename Derived> |
| 4393 | Sema::OwningExprResult |
| 4394 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4395 | CXXFunctionalCastExpr *E) { |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4396 | TypeSourceInfo *OldT; |
| 4397 | TypeSourceInfo *NewT; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | { |
| 4399 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4400 | |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4401 | OldT = E->getTypeInfoAsWritten(); |
| 4402 | NewT = getDerived().TransformType(OldT); |
| 4403 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | return SemaRef.ExprError(); |
| 4405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4406 | |
Douglas Gregor | a88cfbf | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4407 | OwningExprResult SubExpr |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4408 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | if (SubExpr.isInvalid()) |
| 4410 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4413 | OldT == NewT && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | return SemaRef.Owned(E->Retain()); |
| 4416 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | // FIXME: The end of the type's source range is wrong |
| 4418 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4419 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9d12503 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4420 | NewT, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4422 | move(SubExpr), |
| 4423 | E->getRParenLoc()); |
| 4424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4426 | template<typename Derived> |
| 4427 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4428 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4429 | if (E->isTypeOperand()) { |
| 4430 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4431 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4433 | if (T.isNull()) |
| 4434 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4436 | if (!getDerived().AlwaysRebuild() && |
| 4437 | T == E->getTypeOperand()) |
| 4438 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4441 | /*FIXME:*/E->getLocStart(), |
| 4442 | T, |
| 4443 | E->getLocEnd()); |
| 4444 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | // We don't know whether the expression is potentially evaluated until |
| 4447 | // after we perform semantic analysis, so the expression is potentially |
| 4448 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4449 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4450 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4453 | if (SubExpr.isInvalid()) |
| 4454 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | if (!getDerived().AlwaysRebuild() && |
| 4457 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | return SemaRef.Owned(E->Retain()); |
| 4459 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4461 | /*FIXME:*/E->getLocStart(), |
| 4462 | move(SubExpr), |
| 4463 | E->getLocEnd()); |
| 4464 | } |
| 4465 | |
| 4466 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4468 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | template<typename Derived> |
| 4473 | Sema::OwningExprResult |
| 4474 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4475 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4477 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | template<typename Derived> |
| 4480 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4481 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4484 | QualType T = getDerived().TransformType(E->getType()); |
| 4485 | if (T.isNull()) |
| 4486 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | if (!getDerived().AlwaysRebuild() && |
| 4489 | T == E->getType()) |
| 4490 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4491 | |
Douglas Gregor | 828a197 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4492 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4493 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4495 | template<typename Derived> |
| 4496 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4497 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4499 | if (SubExpr.isInvalid()) |
| 4500 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | if (!getDerived().AlwaysRebuild() && |
| 4503 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4505 | |
| 4506 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4507 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | template<typename Derived> |
| 4510 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4511 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4513 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4514 | if (!Param) |
| 4515 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4516 | |
Chandler Carruth | 53cb6f8 | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4517 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | Param == E->getParam()) |
| 4519 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4520 | |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4521 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | template<typename Derived> |
| 4525 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4526 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4527 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4528 | |
| 4529 | QualType T = getDerived().TransformType(E->getType()); |
| 4530 | if (T.isNull()) |
| 4531 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4533 | if (!getDerived().AlwaysRebuild() && |
| 4534 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4535 | return SemaRef.Owned(E->Retain()); |
| 4536 | |
| 4537 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4538 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4539 | T, |
| 4540 | E->getRParenLoc()); |
| 4541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | template<typename Derived> |
| 4544 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4545 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | // Transform the type that we're allocating |
| 4547 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4548 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4549 | if (AllocType.isNull()) |
| 4550 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4552 | // Transform the size of the array we're allocating (if any). |
| 4553 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4554 | if (ArraySize.isInvalid()) |
| 4555 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | // Transform the placement arguments (if any). |
| 4558 | bool ArgumentChanged = false; |
| 4559 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4560 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4561 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4562 | if (Arg.isInvalid()) |
| 4563 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4566 | PlacementArgs.push_back(Arg.take()); |
| 4567 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4568 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4569 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4571 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4572 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4573 | if (Arg.isInvalid()) |
| 4574 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4575 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4576 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4577 | ConstructorArgs.push_back(Arg.take()); |
| 4578 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4579 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4580 | if (!getDerived().AlwaysRebuild() && |
| 4581 | AllocType == E->getAllocatedType() && |
| 4582 | ArraySize.get() == E->getArraySize() && |
| 4583 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | return SemaRef.Owned(E->Retain()); |
| 4585 | |
Douglas Gregor | 5b5ad84 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4586 | if (!ArraySize.get()) { |
| 4587 | // If no array size was specified, but the new expression was |
| 4588 | // instantiated with an array type (e.g., "new T" where T is |
| 4589 | // instantiated with "int[4]"), extract the outer bound from the |
| 4590 | // array type as our array size. We do this with constant and |
| 4591 | // dependently-sized array types. |
| 4592 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4593 | if (!ArrayT) { |
| 4594 | // Do nothing |
| 4595 | } else if (const ConstantArrayType *ConsArrayT |
| 4596 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4597 | ArraySize |
| 4598 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4599 | ConsArrayT->getSize(), |
| 4600 | SemaRef.Context.getSizeType(), |
| 4601 | /*FIXME:*/E->getLocStart())); |
| 4602 | AllocType = ConsArrayT->getElementType(); |
| 4603 | } else if (const DependentSizedArrayType *DepArrayT |
| 4604 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4605 | if (DepArrayT->getSizeExpr()) { |
| 4606 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4607 | AllocType = DepArrayT->getElementType(); |
| 4608 | } |
| 4609 | } |
| 4610 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4612 | E->isGlobalNew(), |
| 4613 | /*FIXME:*/E->getLocStart(), |
| 4614 | move_arg(PlacementArgs), |
| 4615 | /*FIXME:*/E->getLocStart(), |
| 4616 | E->isParenTypeId(), |
| 4617 | AllocType, |
| 4618 | /*FIXME:*/E->getLocStart(), |
| 4619 | /*FIXME:*/SourceRange(), |
| 4620 | move(ArraySize), |
| 4621 | /*FIXME:*/E->getLocStart(), |
| 4622 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4623 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4624 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4625 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4626 | template<typename Derived> |
| 4627 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4628 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4629 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4630 | if (Operand.isInvalid()) |
| 4631 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | Operand.get() == E->getArgument()) |
| 4635 | return SemaRef.Owned(E->Retain()); |
| 4636 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4638 | E->isGlobalDelete(), |
| 4639 | E->isArrayForm(), |
| 4640 | move(Operand)); |
| 4641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4642 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | template<typename Derived> |
| 4644 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4645 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4646 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4647 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4648 | if (Base.isInvalid()) |
| 4649 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4650 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4651 | NestedNameSpecifier *Qualifier |
| 4652 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4653 | E->getQualifierRange()); |
| 4654 | if (E->getQualifier() && !Qualifier) |
| 4655 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4657 | QualType DestroyedType; |
| 4658 | { |
| 4659 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4660 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4661 | if (DestroyedType.isNull()) |
| 4662 | return SemaRef.ExprError(); |
| 4663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4665 | if (!getDerived().AlwaysRebuild() && |
| 4666 | Base.get() == E->getBase() && |
| 4667 | Qualifier == E->getQualifier() && |
| 4668 | DestroyedType == E->getDestroyedType()) |
| 4669 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4671 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4672 | E->getOperatorLoc(), |
| 4673 | E->isArrow(), |
| 4674 | E->getDestroyedTypeLoc(), |
| 4675 | DestroyedType, |
| 4676 | Qualifier, |
| 4677 | E->getQualifierRange()); |
| 4678 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4680 | template<typename Derived> |
| 4681 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4682 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4683 | UnresolvedLookupExpr *Old) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4684 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4685 | |
| 4686 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4687 | Sema::LookupOrdinaryName); |
| 4688 | |
| 4689 | // Transform all the decls. |
| 4690 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4691 | E = Old->decls_end(); I != E; ++I) { |
| 4692 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4693 | if (!InstD) { |
| 4694 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4695 | // This can happen because of dependent hiding. |
| 4696 | if (isa<UsingShadowDecl>(*I)) |
| 4697 | continue; |
| 4698 | else |
| 4699 | return SemaRef.ExprError(); |
| 4700 | } |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4701 | |
| 4702 | // Expand using declarations. |
| 4703 | if (isa<UsingDecl>(InstD)) { |
| 4704 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4705 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4706 | E = UD->shadow_end(); I != E; ++I) |
| 4707 | R.addDecl(*I); |
| 4708 | continue; |
| 4709 | } |
| 4710 | |
| 4711 | R.addDecl(InstD); |
| 4712 | } |
| 4713 | |
| 4714 | // Resolve a kind, but don't do any further analysis. If it's |
| 4715 | // ambiguous, the callee needs to deal with it. |
| 4716 | R.resolveKind(); |
| 4717 | |
| 4718 | // Rebuild the nested-name qualifier, if present. |
| 4719 | CXXScopeSpec SS; |
| 4720 | NestedNameSpecifier *Qualifier = 0; |
| 4721 | if (Old->getQualifier()) { |
| 4722 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4723 | Old->getQualifierRange()); |
| 4724 | if (!Qualifier) |
| 4725 | return SemaRef.ExprError(); |
| 4726 | |
| 4727 | SS.setScopeRep(Qualifier); |
| 4728 | SS.setRange(Old->getQualifierRange()); |
| 4729 | } |
| 4730 | |
| 4731 | // If we have no template arguments, it's a normal declaration name. |
| 4732 | if (!Old->hasExplicitTemplateArgs()) |
| 4733 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4734 | |
| 4735 | // If we have template arguments, rebuild them, then rebuild the |
| 4736 | // templateid expression. |
| 4737 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4738 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4739 | TemplateArgumentLoc Loc; |
| 4740 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4741 | return SemaRef.ExprError(); |
| 4742 | TransArgs.addArgument(Loc); |
| 4743 | } |
| 4744 | |
| 4745 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4746 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4749 | template<typename Derived> |
| 4750 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4751 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4754 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4755 | if (T.isNull()) |
| 4756 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4757 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4758 | if (!getDerived().AlwaysRebuild() && |
| 4759 | T == E->getQueriedType()) |
| 4760 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4761 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4762 | // FIXME: Bad location information |
| 4763 | SourceLocation FakeLParenLoc |
| 4764 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | |
| 4766 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | E->getLocStart(), |
| 4768 | /*FIXME:*/FakeLParenLoc, |
| 4769 | T, |
| 4770 | E->getLocEnd()); |
| 4771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | template<typename Derived> |
| 4774 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4775 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4776 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4777 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4778 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4779 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | if (!NNS) |
| 4781 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
| 4783 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4784 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4785 | if (!Name) |
| 4786 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4788 | if (!E->hasExplicitTemplateArgs()) { |
| 4789 | if (!getDerived().AlwaysRebuild() && |
| 4790 | NNS == E->getQualifier() && |
| 4791 | Name == E->getDeclName()) |
| 4792 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4793 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4794 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4795 | E->getQualifierRange(), |
| 4796 | Name, E->getLocation(), |
| 4797 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4798 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4799 | |
| 4800 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4802 | TemplateArgumentLoc Loc; |
| 4803 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4804 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4805 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4808 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4809 | E->getQualifierRange(), |
| 4810 | Name, E->getLocation(), |
| 4811 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | template<typename Derived> |
| 4815 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4816 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | 321725d | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4817 | // CXXConstructExprs are always implicit, so when we have a |
| 4818 | // 1-argument construction we just transform that argument. |
| 4819 | if (E->getNumArgs() == 1 || |
| 4820 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 4821 | return getDerived().TransformExpr(E->getArg(0)); |
| 4822 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4823 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4824 | |
| 4825 | QualType T = getDerived().TransformType(E->getType()); |
| 4826 | if (T.isNull()) |
| 4827 | return SemaRef.ExprError(); |
| 4828 | |
| 4829 | CXXConstructorDecl *Constructor |
| 4830 | = cast_or_null<CXXConstructorDecl>( |
| 4831 | getDerived().TransformDecl(E->getConstructor())); |
| 4832 | if (!Constructor) |
| 4833 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4834 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4835 | bool ArgumentChanged = false; |
| 4836 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | ArgEnd = E->arg_end(); |
| 4839 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 6eef519 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4840 | if (getDerived().DropCallArgument(*Arg)) { |
| 4841 | ArgumentChanged = true; |
| 4842 | break; |
| 4843 | } |
| 4844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4845 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4846 | if (TransArg.isInvalid()) |
| 4847 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4848 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4849 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4850 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4851 | } |
| 4852 | |
| 4853 | if (!getDerived().AlwaysRebuild() && |
| 4854 | T == E->getType() && |
| 4855 | Constructor == E->getConstructor() && |
| 4856 | !ArgumentChanged) |
| 4857 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | 4411d2e | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4859 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4860 | Constructor, E->isElidable(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4861 | move_arg(Args)); |
| 4862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4864 | /// \brief Transform a C++ temporary-binding expression. |
| 4865 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4866 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4867 | /// transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4868 | template<typename Derived> |
| 4869 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4870 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4871 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4873 | |
Anders Carlsson | eb60edf | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 4874 | /// \brief Transform a C++ reference-binding expression. |
| 4875 | /// |
| 4876 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 4877 | /// transform the subexpression and return that. |
| 4878 | template<typename Derived> |
| 4879 | Sema::OwningExprResult |
| 4880 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 4881 | return getDerived().TransformExpr(E->getSubExpr()); |
| 4882 | } |
| 4883 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4884 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4885 | /// be destroyed after the expression is evaluated. |
| 4886 | /// |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4887 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4888 | /// just transform the subexpression and return that. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4889 | template<typename Derived> |
| 4890 | Sema::OwningExprResult |
| 4891 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 5132655 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4892 | CXXExprWithTemporaries *E) { |
| 4893 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4895 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | template<typename Derived> |
| 4897 | Sema::OwningExprResult |
| 4898 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4899 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4900 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4901 | QualType T = getDerived().TransformType(E->getType()); |
| 4902 | if (T.isNull()) |
| 4903 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | CXXConstructorDecl *Constructor |
| 4906 | = cast_or_null<CXXConstructorDecl>( |
| 4907 | getDerived().TransformDecl(E->getConstructor())); |
| 4908 | if (!Constructor) |
| 4909 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4911 | bool ArgumentChanged = false; |
| 4912 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4913 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4915 | ArgEnd = E->arg_end(); |
| 4916 | Arg != ArgEnd; ++Arg) { |
| 4917 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4918 | if (TransArg.isInvalid()) |
| 4919 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4922 | Args.push_back((Expr *)TransArg.release()); |
| 4923 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4924 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4925 | if (!getDerived().AlwaysRebuild() && |
| 4926 | T == E->getType() && |
| 4927 | Constructor == E->getConstructor() && |
| 4928 | !ArgumentChanged) |
| 4929 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4930 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4931 | // FIXME: Bogus location information |
| 4932 | SourceLocation CommaLoc; |
| 4933 | if (Args.size() > 1) { |
| 4934 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4936 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4937 | } |
| 4938 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4939 | T, |
| 4940 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4941 | move_arg(Args), |
| 4942 | &CommaLoc, |
| 4943 | E->getLocEnd()); |
| 4944 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4945 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4946 | template<typename Derived> |
| 4947 | Sema::OwningExprResult |
| 4948 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4949 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4950 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4951 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4952 | if (T.isNull()) |
| 4953 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4954 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4955 | bool ArgumentChanged = false; |
| 4956 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4957 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4958 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4959 | ArgEnd = E->arg_end(); |
| 4960 | Arg != ArgEnd; ++Arg) { |
| 4961 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4962 | if (TransArg.isInvalid()) |
| 4963 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4964 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4965 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4966 | FakeCommaLocs.push_back( |
| 4967 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4968 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4969 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4971 | if (!getDerived().AlwaysRebuild() && |
| 4972 | T == E->getTypeAsWritten() && |
| 4973 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4974 | return SemaRef.Owned(E->Retain()); |
| 4975 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4976 | // FIXME: we're faking the locations of the commas |
| 4977 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4978 | T, |
| 4979 | E->getLParenLoc(), |
| 4980 | move_arg(Args), |
| 4981 | FakeCommaLocs.data(), |
| 4982 | E->getRParenLoc()); |
| 4983 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4984 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4985 | template<typename Derived> |
| 4986 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4987 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4988 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4989 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4990 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4991 | Expr *OldBase; |
| 4992 | QualType BaseType; |
| 4993 | QualType ObjectType; |
| 4994 | if (!E->isImplicitAccess()) { |
| 4995 | OldBase = E->getBase(); |
| 4996 | Base = getDerived().TransformExpr(OldBase); |
| 4997 | if (Base.isInvalid()) |
| 4998 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4999 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5000 | // Start the member reference and compute the object's type. |
| 5001 | Sema::TypeTy *ObjectTy = 0; |
| 5002 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5003 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5004 | E->isArrow()? tok::arrow : tok::period, |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5005 | ObjectTy); |
| 5006 | if (Base.isInvalid()) |
| 5007 | return SemaRef.ExprError(); |
| 5008 | |
| 5009 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5010 | BaseType = ((Expr*) Base.get())->getType(); |
| 5011 | } else { |
| 5012 | OldBase = 0; |
| 5013 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5014 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5015 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5017 | // Transform the first part of the nested-name-specifier that qualifies |
| 5018 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5019 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5020 | = getDerived().TransformFirstQualifierInScope( |
| 5021 | E->getFirstQualifierFoundInScope(), |
| 5022 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5023 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5024 | NestedNameSpecifier *Qualifier = 0; |
| 5025 | if (E->getQualifier()) { |
| 5026 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5027 | E->getQualifierRange(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5028 | ObjectType, |
| 5029 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5030 | if (!Qualifier) |
| 5031 | return SemaRef.ExprError(); |
| 5032 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5033 | |
| 5034 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5035 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5036 | ObjectType); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5037 | if (!Name) |
| 5038 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5039 | |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5040 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5041 | // This is a reference to a member without an explicitly-specified |
| 5042 | // template argument list. Optimize for this common case. |
| 5043 | if (!getDerived().AlwaysRebuild() && |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5044 | Base.get() == OldBase && |
| 5045 | BaseType == E->getBaseType() && |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5046 | Qualifier == E->getQualifier() && |
| 5047 | Name == E->getMember() && |
| 5048 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | return SemaRef.Owned(E->Retain()); |
| 5050 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5051 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5052 | BaseType, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5053 | E->isArrow(), |
| 5054 | E->getOperatorLoc(), |
| 5055 | Qualifier, |
| 5056 | E->getQualifierRange(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5057 | FirstQualifierInScope, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5058 | Name, |
| 5059 | E->getMemberLoc(), |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5060 | /*TemplateArgs*/ 0); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5063 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5064 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5065 | TemplateArgumentLoc Loc; |
| 5066 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5067 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5068 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5070 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5071 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5072 | BaseType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5073 | E->isArrow(), |
| 5074 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5075 | Qualifier, |
| 5076 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5077 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5078 | Name, |
| 5079 | E->getMemberLoc(), |
| 5080 | &TransArgs); |
| 5081 | } |
| 5082 | |
| 5083 | template<typename Derived> |
| 5084 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5085 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5086 | // Transform the base of the expression. |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5087 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5088 | QualType BaseType; |
| 5089 | if (!Old->isImplicitAccess()) { |
| 5090 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5091 | if (Base.isInvalid()) |
| 5092 | return SemaRef.ExprError(); |
| 5093 | BaseType = ((Expr*) Base.get())->getType(); |
| 5094 | } else { |
| 5095 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5096 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5097 | |
| 5098 | NestedNameSpecifier *Qualifier = 0; |
| 5099 | if (Old->getQualifier()) { |
| 5100 | Qualifier |
| 5101 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 5102 | Old->getQualifierRange()); |
| 5103 | if (Qualifier == 0) |
| 5104 | return SemaRef.ExprError(); |
| 5105 | } |
| 5106 | |
| 5107 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5108 | Sema::LookupOrdinaryName); |
| 5109 | |
| 5110 | // Transform all the decls. |
| 5111 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5112 | E = Old->decls_end(); I != E; ++I) { |
| 5113 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5114 | if (!InstD) { |
| 5115 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5116 | // This can happen because of dependent hiding. |
| 5117 | if (isa<UsingShadowDecl>(*I)) |
| 5118 | continue; |
| 5119 | else |
| 5120 | return SemaRef.ExprError(); |
| 5121 | } |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5122 | |
| 5123 | // Expand using declarations. |
| 5124 | if (isa<UsingDecl>(InstD)) { |
| 5125 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5126 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5127 | E = UD->shadow_end(); I != E; ++I) |
| 5128 | R.addDecl(*I); |
| 5129 | continue; |
| 5130 | } |
| 5131 | |
| 5132 | R.addDecl(InstD); |
| 5133 | } |
| 5134 | |
| 5135 | R.resolveKind(); |
| 5136 | |
| 5137 | TemplateArgumentListInfo TransArgs; |
| 5138 | if (Old->hasExplicitTemplateArgs()) { |
| 5139 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5140 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5141 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5142 | TemplateArgumentLoc Loc; |
| 5143 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5144 | Loc)) |
| 5145 | return SemaRef.ExprError(); |
| 5146 | TransArgs.addArgument(Loc); |
| 5147 | } |
| 5148 | } |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5149 | |
| 5150 | // FIXME: to do this check properly, we will need to preserve the |
| 5151 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5152 | // base (and therefore couldn't do the check) and a |
| 5153 | // nested-name-qualifier (and therefore could do the lookup). |
| 5154 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5155 | |
| 5156 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | aa81e16 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5157 | BaseType, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5158 | Old->getOperatorLoc(), |
| 5159 | Old->isArrow(), |
| 5160 | Qualifier, |
| 5161 | Old->getQualifierRange(), |
John McCall | c2233c5 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5162 | FirstQualifierInScope, |
John McCall | 129e2df | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5163 | R, |
| 5164 | (Old->hasExplicitTemplateArgs() |
| 5165 | ? &TransArgs : 0)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | template<typename Derived> |
| 5169 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5170 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | } |
| 5173 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5174 | template<typename Derived> |
| 5175 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5176 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | // FIXME: poor source location |
| 5178 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5179 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5180 | if (EncodedType.isNull()) |
| 5181 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5183 | if (!getDerived().AlwaysRebuild() && |
| 5184 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5186 | |
| 5187 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5188 | EncodedType, |
| 5189 | E->getRParenLoc()); |
| 5190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5191 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | template<typename Derived> |
| 5193 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5194 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5195 | // FIXME: Implement this! |
| 5196 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | template<typename Derived> |
| 5201 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5202 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5203 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | } |
| 5205 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5206 | template<typename Derived> |
| 5207 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5208 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | = cast_or_null<ObjCProtocolDecl>( |
| 5211 | getDerived().TransformDecl(E->getProtocol())); |
| 5212 | if (!Protocol) |
| 5213 | return SemaRef.ExprError(); |
| 5214 | |
| 5215 | if (!getDerived().AlwaysRebuild() && |
| 5216 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | return SemaRef.Owned(E->Retain()); |
| 5218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5220 | E->getAtLoc(), |
| 5221 | /*FIXME:*/E->getAtLoc(), |
| 5222 | /*FIXME:*/E->getAtLoc(), |
| 5223 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5224 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | template<typename Derived> |
| 5228 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5229 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5230 | // FIXME: Implement this! |
| 5231 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5235 | template<typename Derived> |
| 5236 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5237 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5238 | // FIXME: Implement this! |
| 5239 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5240 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | template<typename Derived> |
| 5244 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5245 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5246 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5247 | // FIXME: Implement this! |
| 5248 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | } |
| 5251 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | template<typename Derived> |
| 5253 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5254 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5255 | // FIXME: Implement this! |
| 5256 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | template<typename Derived> |
| 5261 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5262 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5263 | // FIXME: Implement this! |
| 5264 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5265 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5266 | } |
| 5267 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5268 | template<typename Derived> |
| 5269 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5270 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5271 | bool ArgumentChanged = false; |
| 5272 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5273 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5274 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5275 | if (SubExpr.isInvalid()) |
| 5276 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5279 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5280 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5281 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5282 | if (!getDerived().AlwaysRebuild() && |
| 5283 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | return SemaRef.Owned(E->Retain()); |
| 5285 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5286 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5287 | move_arg(SubExprs), |
| 5288 | E->getRParenLoc()); |
| 5289 | } |
| 5290 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5291 | template<typename Derived> |
| 5292 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5293 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5294 | // FIXME: Implement this! |
| 5295 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5296 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5299 | template<typename Derived> |
| 5300 | Sema::OwningExprResult |
John McCall | 454feb9 | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5301 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5302 | // FIXME: Implement this! |
| 5303 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5304 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5306 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5307 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5308 | // Type reconstruction |
| 5309 | //===----------------------------------------------------------------------===// |
| 5310 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5312 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5313 | SourceLocation Star) { |
| 5314 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5315 | getDerived().getBaseEntity()); |
| 5316 | } |
| 5317 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5318 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5319 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5320 | SourceLocation Star) { |
| 5321 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5322 | getDerived().getBaseEntity()); |
| 5323 | } |
| 5324 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5325 | template<typename Derived> |
| 5326 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5327 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5328 | bool WrittenAsLValue, |
| 5329 | SourceLocation Sigil) { |
| 5330 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5331 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5336 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5337 | QualType ClassType, |
| 5338 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5339 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5340 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5345 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5346 | SourceLocation Sigil) { |
| 5347 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5348 | getDerived().getBaseEntity()); |
| 5349 | } |
| 5350 | |
| 5351 | template<typename Derived> |
| 5352 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5353 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5354 | ArrayType::ArraySizeModifier SizeMod, |
| 5355 | const llvm::APInt *Size, |
| 5356 | Expr *SizeExpr, |
| 5357 | unsigned IndexTypeQuals, |
| 5358 | SourceRange BracketsRange) { |
| 5359 | if (SizeExpr || !Size) |
| 5360 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5361 | IndexTypeQuals, BracketsRange, |
| 5362 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5363 | |
| 5364 | QualType Types[] = { |
| 5365 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5366 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5367 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5368 | }; |
| 5369 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5370 | QualType SizeType; |
| 5371 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5372 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5373 | SizeType = Types[I]; |
| 5374 | break; |
| 5375 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5376 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5377 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5378 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5379 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5380 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5382 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5383 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | QualType |
| 5385 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5386 | ArrayType::ArraySizeModifier SizeMod, |
| 5387 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5388 | unsigned IndexTypeQuals, |
| 5389 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5391 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5395 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5396 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5397 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5398 | unsigned IndexTypeQuals, |
| 5399 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5400 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5401 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5402 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5403 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5404 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | QualType |
| 5406 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5407 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5408 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5409 | unsigned IndexTypeQuals, |
| 5410 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5412 | SizeExpr.takeAs<Expr>(), |
| 5413 | IndexTypeQuals, BracketsRange); |
| 5414 | } |
| 5415 | |
| 5416 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | QualType |
| 5418 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5419 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5420 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5421 | unsigned IndexTypeQuals, |
| 5422 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5424 | SizeExpr.takeAs<Expr>(), |
| 5425 | IndexTypeQuals, BracketsRange); |
| 5426 | } |
| 5427 | |
| 5428 | template<typename Derived> |
| 5429 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5430 | unsigned NumElements, |
| 5431 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5432 | // FIXME: semantic checking! |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5433 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5434 | IsAltiVec, IsPixel); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5435 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5436 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5437 | template<typename Derived> |
| 5438 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5439 | unsigned NumElements, |
| 5440 | SourceLocation AttributeLoc) { |
| 5441 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5442 | NumElements, true); |
| 5443 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5445 | AttributeLoc); |
| 5446 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5447 | AttributeLoc); |
| 5448 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5450 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5451 | QualType |
| 5452 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5453 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5454 | SourceLocation AttributeLoc) { |
| 5455 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5456 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5457 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5458 | template<typename Derived> |
| 5459 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5461 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5463 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5464 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5465 | Quals, |
| 5466 | getDerived().getBaseLocation(), |
| 5467 | getDerived().getBaseEntity()); |
| 5468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5470 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5471 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5472 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5473 | } |
| 5474 | |
| 5475 | template<typename Derived> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5476 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5477 | assert(D && "no decl found"); |
| 5478 | if (D->isInvalidDecl()) return QualType(); |
| 5479 | |
| 5480 | TypeDecl *Ty; |
| 5481 | if (isa<UsingDecl>(D)) { |
| 5482 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5483 | assert(Using->isTypeName() && |
| 5484 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5485 | |
| 5486 | // A valid resolved using typename decl points to exactly one type decl. |
| 5487 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5488 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5489 | |
| 5490 | } else { |
| 5491 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5492 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5493 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5494 | } |
| 5495 | |
| 5496 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5497 | } |
| 5498 | |
| 5499 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5500 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5501 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5502 | } |
| 5503 | |
| 5504 | template<typename Derived> |
| 5505 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5506 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5507 | } |
| 5508 | |
| 5509 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5510 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5511 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5512 | } |
| 5513 | |
| 5514 | template<typename Derived> |
| 5515 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5516 | TemplateName Template, |
| 5517 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5518 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5519 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5521 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5522 | template<typename Derived> |
| 5523 | NestedNameSpecifier * |
| 5524 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5525 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5526 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5527 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5528 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5529 | CXXScopeSpec SS; |
| 5530 | // FIXME: The source location information is all wrong. |
| 5531 | SS.setRange(Range); |
| 5532 | SS.setScopeRep(Prefix); |
| 5533 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5534 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5535 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5536 | ObjectType, |
| 5537 | FirstQualifierInScope, |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5538 | false, false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | template<typename Derived> |
| 5542 | NestedNameSpecifier * |
| 5543 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5544 | SourceRange Range, |
| 5545 | NamespaceDecl *NS) { |
| 5546 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5547 | } |
| 5548 | |
| 5549 | template<typename Derived> |
| 5550 | NestedNameSpecifier * |
| 5551 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5552 | SourceRange Range, |
| 5553 | bool TemplateKW, |
| 5554 | QualType T) { |
| 5555 | if (T->isDependentType() || T->isRecordType() || |
| 5556 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5557 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5558 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5559 | T.getTypePtr()); |
| 5560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5561 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5562 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5563 | return 0; |
| 5564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5565 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5566 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5568 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5569 | bool TemplateKW, |
| 5570 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5571 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5572 | Template); |
| 5573 | } |
| 5574 | |
| 5575 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5576 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5577 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5578 | const IdentifierInfo &II, |
| 5579 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5580 | CXXScopeSpec SS; |
| 5581 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5583 | UnqualifiedId Name; |
| 5584 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5585 | return getSema().ActOnDependentTemplateName( |
| 5586 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5587 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5588 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5589 | ObjectType.getAsOpaquePtr(), |
| 5590 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5591 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5594 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5595 | TemplateName |
| 5596 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5597 | OverloadedOperatorKind Operator, |
| 5598 | QualType ObjectType) { |
| 5599 | CXXScopeSpec SS; |
| 5600 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5601 | SS.setScopeRep(Qualifier); |
| 5602 | UnqualifiedId Name; |
| 5603 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5604 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5605 | Operator, SymbolLocations); |
| 5606 | return getSema().ActOnDependentTemplateName( |
| 5607 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5608 | SS, |
| 5609 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5610 | ObjectType.getAsOpaquePtr(), |
| 5611 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5612 | .template getAsVal<TemplateName>(); |
| 5613 | } |
| 5614 | |
| 5615 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5617 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5618 | SourceLocation OpLoc, |
| 5619 | ExprArg Callee, |
| 5620 | ExprArg First, |
| 5621 | ExprArg Second) { |
| 5622 | Expr *FirstExpr = (Expr *)First.get(); |
| 5623 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5624 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5625 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5627 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5628 | if (Op == OO_Subscript) { |
| 5629 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5630 | !SecondExpr->getType()->isOverloadableType()) |
| 5631 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5632 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5633 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5634 | } else if (Op == OO_Arrow) { |
| 5635 | // -> is never a builtin operation. |
| 5636 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5637 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5638 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5639 | // The argument is not of overloadable type, so try to create a |
| 5640 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5641 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5642 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5645 | } |
| 5646 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5647 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5648 | !SecondExpr->getType()->isOverloadableType()) { |
| 5649 | // Neither of the arguments is an overloadable type, so try to |
| 5650 | // create a built-in binary operation. |
| 5651 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5652 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5653 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5654 | if (Result.isInvalid()) |
| 5655 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5657 | First.release(); |
| 5658 | Second.release(); |
| 5659 | return move(Result); |
| 5660 | } |
| 5661 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | |
| 5663 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5664 | // used during overload resolution. |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5665 | UnresolvedSet<16> Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5667 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5668 | assert(ULE->requiresADL()); |
| 5669 | |
| 5670 | // FIXME: Do we have to check |
| 5671 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5672 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5673 | } else { |
John McCall | 6e26689 | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5674 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5675 | } |
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 | // Add any functions found via argument-dependent lookup. |
| 5678 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5679 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5681 | // Create the overloaded operator invocation for unary operators. |
| 5682 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5683 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5685 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5686 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5687 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5688 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5689 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5690 | OpLoc, |
| 5691 | move(First), |
| 5692 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5693 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5695 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5696 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5697 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5698 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5699 | if (Result.isInvalid()) |
| 5700 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5702 | First.release(); |
| 5703 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5705 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5706 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5707 | } // end namespace clang |
| 5708 | |
| 5709 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |