John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | d6ff332 | 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 | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 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 | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | a16548e | 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 | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 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 | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 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 | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | a16548e | 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 | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | d6ff332 | 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 | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 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 | d6ff332 | 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 | d196a58 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 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 | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 194 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | 550e0c2 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | 550e0c2 | 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. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
| 205 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 206 | |
| 207 | /// \brief Transform the given type-with-location into a new |
| 208 | /// type, collecting location information in the given builder |
| 209 | /// as necessary. |
| 210 | /// |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
| 212 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 217 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 218 | /// statement or the TransformExpr() function to transform an expression. |
| 219 | /// Subclasses may override this function to transform statements using some |
| 220 | /// other mechanism. |
| 221 | /// |
| 222 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 227 | /// By default, this routine transforms an expression by delegating to the |
| 228 | /// appropriate TransformXXXExpr function to build a new expression. |
| 229 | /// Subclasses may override this function to transform expressions using some |
| 230 | /// other mechanism. |
| 231 | /// |
| 232 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 235 | /// \brief Transform the given declaration, which is referenced from a type |
| 236 | /// or expression. |
| 237 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 238 | /// By default, acts as the identity function on declarations. Subclasses |
| 239 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 240 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 247 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 250 | /// \brief Transform the given declaration, which was the first part of a |
| 251 | /// nested-name-specifier in a member access expression. |
| 252 | /// |
| 253 | /// This specific declaration transformation only applies to the first |
| 254 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 255 | /// the \c T in \c x->T::member |
| 256 | /// |
| 257 | /// By default, invokes TransformDecl() to transform the declaration. |
| 258 | /// Subclasses may override this function to provide alternate behavior. |
| 259 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 266 | /// nested-name-specifier. Subclasses may override this function to provide |
| 267 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 273 | /// \brief Transform the given declaration name. |
| 274 | /// |
| 275 | /// By default, transforms the types of conversion function, constructor, |
| 276 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 277 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 278 | /// override this function to provide alternate behavior. |
| 279 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | /// By default, this operation transforms the type, expression, or |
| 294 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 295 | /// new template argument from the transformed result. Subclasses may |
| 296 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 297 | /// |
| 298 | /// Returns true if there was an error. |
| 299 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 300 | TemplateArgumentLoc &Output); |
| 301 | |
| 302 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 303 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 304 | TemplateArgumentLoc &ArgLoc); |
| 305 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 306 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 307 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 308 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 314 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 315 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame^] | 318 | /// \brief Transforms the parameters of a function type into the |
| 319 | /// given vectors. |
| 320 | /// |
| 321 | /// The result vectors should be kept in sync; null entries in the |
| 322 | /// variables vector are acceptable. |
| 323 | /// |
| 324 | /// Return true on error. |
| 325 | bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 326 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 327 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars); |
| 328 | |
| 329 | /// \brief Transforms a single function-type parameter. Return null |
| 330 | /// on error. |
| 331 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); |
| 332 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 334 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 336 | QualType |
| 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 342 | #define STMT(Node, Parent) \ |
| 343 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 344 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 345 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 346 | #define ABSTRACT_EXPR(Node, Parent) |
| 347 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 349 | /// \brief Build a new pointer type given its pointee type. |
| 350 | /// |
| 351 | /// By default, performs semantic analysis when building the pointer type. |
| 352 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 353 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 354 | |
| 355 | /// \brief Build a new block pointer type given its pointee type. |
| 356 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 358 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 359 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 360 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 361 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 362 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 363 | /// By default, performs semantic analysis when building the |
| 364 | /// reference type. Subclasses may override this routine to provide |
| 365 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 366 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 367 | /// \param LValue whether the type was written with an lvalue sigil |
| 368 | /// or an rvalue sigil. |
| 369 | QualType RebuildReferenceType(QualType ReferentType, |
| 370 | bool LValue, |
| 371 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 373 | /// \brief Build a new member pointer type given the pointee type and the |
| 374 | /// class type it refers into. |
| 375 | /// |
| 376 | /// By default, performs semantic analysis when building the member pointer |
| 377 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 378 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 379 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 381 | /// \brief Build a new Objective C object pointer type. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 382 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 383 | SourceLocation Sigil); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 384 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 385 | /// \brief Build a new array type given the element type, size |
| 386 | /// modifier, size of the array (if known), size expression, and index type |
| 387 | /// qualifiers. |
| 388 | /// |
| 389 | /// By default, performs semantic analysis when building the array type. |
| 390 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 392 | QualType RebuildArrayType(QualType ElementType, |
| 393 | ArrayType::ArraySizeModifier SizeMod, |
| 394 | const llvm::APInt *Size, |
| 395 | Expr *SizeExpr, |
| 396 | unsigned IndexTypeQuals, |
| 397 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 399 | /// \brief Build a new constant array type given the element type, size |
| 400 | /// modifier, (known) size of the array, and index type qualifiers. |
| 401 | /// |
| 402 | /// By default, performs semantic analysis when building the array type. |
| 403 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | ArrayType::ArraySizeModifier SizeMod, |
| 406 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 407 | unsigned IndexTypeQuals, |
| 408 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 409 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | /// \brief Build a new incomplete array type given the element type, size |
| 411 | /// modifier, and index type qualifiers. |
| 412 | /// |
| 413 | /// By default, performs semantic analysis when building the array type. |
| 414 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 417 | unsigned IndexTypeQuals, |
| 418 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 419 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | /// size modifier, size expression, and index type qualifiers. |
| 422 | /// |
| 423 | /// By default, performs semantic analysis when building the array type. |
| 424 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 426 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 427 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 428 | unsigned IndexTypeQuals, |
| 429 | SourceRange BracketsRange); |
| 430 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 432 | /// size modifier, size expression, and index type qualifiers. |
| 433 | /// |
| 434 | /// By default, performs semantic analysis when building the array type. |
| 435 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 436 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 437 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 438 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 439 | unsigned IndexTypeQuals, |
| 440 | SourceRange BracketsRange); |
| 441 | |
| 442 | /// \brief Build a new vector type given the element type and |
| 443 | /// 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. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 447 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 448 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new extended vector type given the element type and |
| 451 | /// number of elements. |
| 452 | /// |
| 453 | /// By default, performs semantic analysis when building the vector type. |
| 454 | /// Subclasses may override this routine to provide different behavior. |
| 455 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 456 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | |
| 458 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 459 | /// given the element type and number of elements. |
| 460 | /// |
| 461 | /// By default, performs semantic analysis when building the vector type. |
| 462 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 464 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 465 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 467 | /// \brief Build a new function type. |
| 468 | /// |
| 469 | /// By default, performs semantic analysis when building the function type. |
| 470 | /// Subclasses may override this routine to provide different behavior. |
| 471 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 473 | unsigned NumParamTypes, |
| 474 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 476 | /// \brief Build a new unprototyped function type. |
| 477 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 478 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 479 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 480 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 481 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 482 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 483 | /// \brief Build a new typedef type. |
| 484 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 485 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 486 | } |
| 487 | |
| 488 | /// \brief Build a new class/struct/union type. |
| 489 | QualType RebuildRecordType(RecordDecl *Record) { |
| 490 | return SemaRef.Context.getTypeDeclType(Record); |
| 491 | } |
| 492 | |
| 493 | /// \brief Build a new Enum type. |
| 494 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 495 | return SemaRef.Context.getTypeDeclType(Enum); |
| 496 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 497 | |
| 498 | /// \brief Build a new elaborated type. |
| 499 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 500 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 501 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
| 503 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 504 | /// |
| 505 | /// By default, performs semantic analysis when building the typeof type. |
| 506 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 507 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 508 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 510 | /// |
| 511 | /// By default, builds a new TypeOfType with the given underlying type. |
| 512 | QualType RebuildTypeOfType(QualType Underlying); |
| 513 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 515 | /// |
| 516 | /// By default, performs semantic analysis when building the decltype type. |
| 517 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 518 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 520 | /// \brief Build a new template specialization type. |
| 521 | /// |
| 522 | /// By default, performs semantic analysis when building the template |
| 523 | /// specialization type. Subclasses may override this routine to provide |
| 524 | /// different behavior. |
| 525 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 526 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 527 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 529 | /// \brief Build a new qualified name type. |
| 530 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | /// By default, builds a new QualifiedNameType type from the |
| 532 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | /// this routine to provide different behavior. |
| 534 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 535 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 537 | |
| 538 | /// \brief Build a new typename type that refers to a template-id. |
| 539 | /// |
| 540 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 541 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 542 | /// different behavior. |
| 543 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 544 | if (NNS->isDependent()) { |
| 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
| 548 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 552 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 554 | |
| 555 | /// \brief Build a new typename type that refers to an identifier. |
| 556 | /// |
| 557 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 558 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 559 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 561 | const IdentifierInfo *Id, |
| 562 | SourceRange SR) { |
| 563 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 566 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 567 | /// identifier that names the next step in the nested-name-specifier. |
| 568 | /// |
| 569 | /// By default, performs semantic analysis when building the new |
| 570 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 571 | /// different behavior. |
| 572 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 573 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 574 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 575 | QualType ObjectType, |
| 576 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 577 | |
| 578 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 579 | /// namespace named in the next step in the nested-name-specifier. |
| 580 | /// |
| 581 | /// By default, performs semantic analysis when building the new |
| 582 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 583 | /// different behavior. |
| 584 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 585 | SourceRange Range, |
| 586 | NamespaceDecl *NS); |
| 587 | |
| 588 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 589 | /// type named in the next step in the nested-name-specifier. |
| 590 | /// |
| 591 | /// By default, performs semantic analysis when building the new |
| 592 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 593 | /// different behavior. |
| 594 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 595 | SourceRange Range, |
| 596 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 597 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 598 | |
| 599 | /// \brief Build a new template name given a nested name specifier, a flag |
| 600 | /// indicating whether the "template" keyword was provided, and the template |
| 601 | /// that the template name refers to. |
| 602 | /// |
| 603 | /// By default, builds the new template name directly. Subclasses may override |
| 604 | /// this routine to provide different behavior. |
| 605 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 606 | bool TemplateKW, |
| 607 | TemplateDecl *Template); |
| 608 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 609 | /// \brief Build a new template name given a nested name specifier and the |
| 610 | /// name that is referred to as a template. |
| 611 | /// |
| 612 | /// By default, performs semantic analysis to determine whether the name can |
| 613 | /// be resolved to a specific template, then builds the appropriate kind of |
| 614 | /// template name. Subclasses may override this routine to provide different |
| 615 | /// behavior. |
| 616 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 617 | const IdentifierInfo &II, |
| 618 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 620 | /// \brief Build a new template name given a nested name specifier and the |
| 621 | /// overloaded operator name that is referred to as a template. |
| 622 | /// |
| 623 | /// By default, performs semantic analysis to determine whether the name can |
| 624 | /// be resolved to a specific template, then builds the appropriate kind of |
| 625 | /// template name. Subclasses may override this routine to provide different |
| 626 | /// behavior. |
| 627 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 628 | OverloadedOperatorKind Operator, |
| 629 | QualType ObjectType); |
| 630 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 631 | /// \brief Build a new compound statement. |
| 632 | /// |
| 633 | /// By default, performs semantic analysis to build the new statement. |
| 634 | /// Subclasses may override this routine to provide different behavior. |
| 635 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 636 | MultiStmtArg Statements, |
| 637 | SourceLocation RBraceLoc, |
| 638 | bool IsStmtExpr) { |
| 639 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 640 | IsStmtExpr); |
| 641 | } |
| 642 | |
| 643 | /// \brief Build a new case statement. |
| 644 | /// |
| 645 | /// By default, performs semantic analysis to build the new statement. |
| 646 | /// Subclasses may override this routine to provide different behavior. |
| 647 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 648 | ExprArg LHS, |
| 649 | SourceLocation EllipsisLoc, |
| 650 | ExprArg RHS, |
| 651 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 653 | ColonLoc); |
| 654 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 656 | /// \brief Attach the body to a new case statement. |
| 657 | /// |
| 658 | /// By default, performs semantic analysis to build the new statement. |
| 659 | /// Subclasses may override this routine to provide different behavior. |
| 660 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 661 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 662 | return move(S); |
| 663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 665 | /// \brief Build a new default statement. |
| 666 | /// |
| 667 | /// By default, performs semantic analysis to build the new statement. |
| 668 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 670 | SourceLocation ColonLoc, |
| 671 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 673 | /*CurScope=*/0); |
| 674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 675 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 676 | /// \brief Build a new label statement. |
| 677 | /// |
| 678 | /// By default, performs semantic analysis to build the new statement. |
| 679 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 680 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 681 | IdentifierInfo *Id, |
| 682 | SourceLocation ColonLoc, |
| 683 | StmtArg SubStmt) { |
| 684 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 685 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 687 | /// \brief Build a new "if" statement. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis to build the new statement. |
| 690 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 691 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 692 | VarDecl *CondVar, StmtArg Then, |
| 693 | SourceLocation ElseLoc, StmtArg Else) { |
| 694 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 695 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 696 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 698 | /// \brief Start building a new switch statement. |
| 699 | /// |
| 700 | /// By default, performs semantic analysis to build the new statement. |
| 701 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 702 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 703 | VarDecl *CondVar) { |
| 704 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 707 | /// \brief Attach the body to the switch statement. |
| 708 | /// |
| 709 | /// By default, performs semantic analysis to build the new statement. |
| 710 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 712 | StmtArg Switch, StmtArg Body) { |
| 713 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 714 | move(Body)); |
| 715 | } |
| 716 | |
| 717 | /// \brief Build a new while statement. |
| 718 | /// |
| 719 | /// By default, performs semantic analysis to build the new statement. |
| 720 | /// Subclasses may override this routine to provide different behavior. |
| 721 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 722 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 723 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 725 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 726 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 729 | /// \brief Build a new do-while statement. |
| 730 | /// |
| 731 | /// By default, performs semantic analysis to build the new statement. |
| 732 | /// Subclasses may override this routine to provide different behavior. |
| 733 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 734 | SourceLocation WhileLoc, |
| 735 | SourceLocation LParenLoc, |
| 736 | ExprArg Cond, |
| 737 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 739 | move(Cond), RParenLoc); |
| 740 | } |
| 741 | |
| 742 | /// \brief Build a new for statement. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis to build the new statement. |
| 745 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 748 | StmtArg Init, Sema::FullExprArg Cond, |
| 749 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 750 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 751 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 752 | DeclPtrTy::make(CondVar), |
| 753 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 756 | /// \brief Build a new goto statement. |
| 757 | /// |
| 758 | /// By default, performs semantic analysis to build the new statement. |
| 759 | /// Subclasses may override this routine to provide different behavior. |
| 760 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 761 | SourceLocation LabelLoc, |
| 762 | LabelStmt *Label) { |
| 763 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 764 | } |
| 765 | |
| 766 | /// \brief Build a new indirect goto statement. |
| 767 | /// |
| 768 | /// By default, performs semantic analysis to build the new statement. |
| 769 | /// Subclasses may override this routine to provide different behavior. |
| 770 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 771 | SourceLocation StarLoc, |
| 772 | ExprArg Target) { |
| 773 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 774 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | /// \brief Build a new return statement. |
| 777 | /// |
| 778 | /// By default, performs semantic analysis to build the new statement. |
| 779 | /// Subclasses may override this routine to provide different behavior. |
| 780 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 781 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 783 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 784 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 786 | /// \brief Build a new declaration statement. |
| 787 | /// |
| 788 | /// By default, performs semantic analysis to build the new statement. |
| 789 | /// Subclasses may override this routine to provide different behavior. |
| 790 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 792 | SourceLocation EndLoc) { |
| 793 | return getSema().Owned( |
| 794 | new (getSema().Context) DeclStmt( |
| 795 | DeclGroupRef::Create(getSema().Context, |
| 796 | Decls, NumDecls), |
| 797 | StartLoc, EndLoc)); |
| 798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 800 | /// \brief Build a new inline asm statement. |
| 801 | /// |
| 802 | /// By default, performs semantic analysis to build the new statement. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
| 804 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 805 | bool IsSimple, |
| 806 | bool IsVolatile, |
| 807 | unsigned NumOutputs, |
| 808 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 809 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 810 | MultiExprArg Constraints, |
| 811 | MultiExprArg Exprs, |
| 812 | ExprArg AsmString, |
| 813 | MultiExprArg Clobbers, |
| 814 | SourceLocation RParenLoc, |
| 815 | bool MSAsm) { |
| 816 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 817 | NumInputs, Names, move(Constraints), |
| 818 | move(Exprs), move(AsmString), move(Clobbers), |
| 819 | RParenLoc, MSAsm); |
| 820 | } |
| 821 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 822 | /// \brief Build a new C++ exception declaration. |
| 823 | /// |
| 824 | /// By default, performs semantic analysis to build the new decaration. |
| 825 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 827 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 828 | IdentifierInfo *Name, |
| 829 | SourceLocation Loc, |
| 830 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 832 | TypeRange); |
| 833 | } |
| 834 | |
| 835 | /// \brief Build a new C++ catch statement. |
| 836 | /// |
| 837 | /// By default, performs semantic analysis to build the new statement. |
| 838 | /// Subclasses may override this routine to provide different behavior. |
| 839 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 840 | VarDecl *ExceptionDecl, |
| 841 | StmtArg Handler) { |
| 842 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 844 | Handler.takeAs<Stmt>())); |
| 845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 847 | /// \brief Build a new C++ try statement. |
| 848 | /// |
| 849 | /// By default, performs semantic analysis to build the new statement. |
| 850 | /// Subclasses may override this routine to provide different behavior. |
| 851 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 852 | StmtArg TryBlock, |
| 853 | MultiStmtArg Handlers) { |
| 854 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 857 | /// \brief Build a new expression that references a declaration. |
| 858 | /// |
| 859 | /// By default, performs semantic analysis to build the new expression. |
| 860 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 861 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 862 | LookupResult &R, |
| 863 | bool RequiresADL) { |
| 864 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 865 | } |
| 866 | |
| 867 | |
| 868 | /// \brief Build a new expression that references a declaration. |
| 869 | /// |
| 870 | /// By default, performs semantic analysis to build the new expression. |
| 871 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 872 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 873 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 874 | ValueDecl *VD, SourceLocation Loc, |
| 875 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 876 | CXXScopeSpec SS; |
| 877 | SS.setScopeRep(Qualifier); |
| 878 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 879 | |
| 880 | // FIXME: loses template args. |
| 881 | |
| 882 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 885 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 886 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 887 | /// By default, performs semantic analysis to build the new expression. |
| 888 | /// Subclasses may override this routine to provide different behavior. |
| 889 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 890 | SourceLocation RParen) { |
| 891 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 892 | } |
| 893 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 894 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 896 | /// By default, performs semantic analysis to build the new expression. |
| 897 | /// Subclasses may override this routine to provide different behavior. |
| 898 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 899 | SourceLocation OperatorLoc, |
| 900 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 901 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 902 | SourceRange QualifierRange, |
| 903 | TypeSourceInfo *ScopeType, |
| 904 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 905 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 906 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 907 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 908 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | /// |
Douglas Gregor | a16548e | 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 | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 915 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 918 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | /// |
Douglas Gregor | a16548e | 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 | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 922 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 923 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 924 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 925 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 929 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | OwningExprResult Result |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 940 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 941 | SubExpr.release(); |
| 942 | return move(Result); |
| 943 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 949 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 955 | RBracketLoc); |
| 956 | } |
| 957 | |
| 958 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 959 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 976 | NestedNameSpecifier *Qualifier, |
| 977 | SourceRange QualifierRange, |
| 978 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 979 | ValueDecl *Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 980 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 981 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 986 | Expr *BaseExpr = Base.takeAs<Expr>(); |
Douglas Gregor | cc3f325 | 2010-03-03 23:55:11 +0000 | [diff] [blame] | 987 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 988 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 989 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 991 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | |
Douglas Gregor | f405d7e | 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 | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1003 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1004 | |
John McCall | 38836f0 | 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 | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1010 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1011 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1012 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1013 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | /// |
Douglas Gregor | a16548e | 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 | 5287f09 | 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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | move(LHS), move(RHS)); |
| 1038 | } |
| 1039 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1040 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | /// |
Douglas Gregor | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1044 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1045 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | SourceLocation RParenLoc, |
| 1047 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1048 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1049 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1051 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1052 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | /// |
Douglas Gregor | a16548e | 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 | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1057 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | SourceLocation RParenLoc, |
| 1059 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1060 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1061 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1064 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1065 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1069 | SourceLocation OpLoc, |
| 1070 | SourceLocation AccessorLoc, |
| 1071 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1072 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1073 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 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 | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1076 | OpLoc, /*IsArrow*/ false, |
| 1077 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1078 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1079 | AccessorLoc, |
| 1080 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1081 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1083 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | /// |
Douglas Gregor | a16548e | 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 | d3d9306 | 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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | ArrayExprs.release(); |
| 1119 | return move(Result); |
| 1120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1123 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1131 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | RParenLoc); |
| 1139 | } |
| 1140 | |
| 1141 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | /// |
Douglas Gregor | a16548e | 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 | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1148 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1149 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1152 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | /// |
| 1154 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1163 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 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 | 11289f4 | 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 | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1221 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1228 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | move(SubExpr), RParenLoc); |
| 1231 | |
| 1232 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1233 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1235 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1238 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | RAngleLoc, LParenLoc, |
| 1240 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1244 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1246 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | default: |
| 1249 | assert(false && "Invalid C++ named cast"); |
| 1250 | break; |
| 1251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1252 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1253 | return getSema().ExprError(); |
| 1254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1255 | |
Douglas Gregor | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1262 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | SourceLocation RAngleLoc, |
| 1264 | SourceLocation LParenLoc, |
| 1265 | ExprArg SubExpr, |
| 1266 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 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 | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1279 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | SourceLocation RAngleLoc, |
| 1281 | SourceLocation LParenLoc, |
| 1282 | ExprArg SubExpr, |
| 1283 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 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 | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1296 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1297 | SourceLocation RAngleLoc, |
| 1298 | SourceLocation LParenLoc, |
| 1299 | ExprArg SubExpr, |
| 1300 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 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 | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1313 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | SourceLocation RAngleLoc, |
| 1315 | SourceLocation LParenLoc, |
| 1316 | ExprArg SubExpr, |
| 1317 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1322 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Douglas Gregor | a16548e | 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 | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1329 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | SourceLocation LParenLoc, |
| 1331 | ExprArg SubExpr, |
| 1332 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1333 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1335 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1337 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | RParenLoc); |
| 1340 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1351 | T.getAsOpaquePtr(), RParenLoc); |
| 1352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | OwningExprResult Result |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1369 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1378 | QualType ThisType, |
| 1379 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1381 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1382 | isImplicit)); |
Douglas Gregor | a16548e | 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 | 033f675 | 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 | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | SourceLocation LParenLoc, |
| 1410 | QualType T, |
| 1411 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | 0, RParenLoc); |
| 1416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | bool UseGlobal, |
| 1424 | SourceLocation PlacementLParen, |
| 1425 | MultiExprArg PlacementArgs, |
| 1426 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | bool ParenTypeId, |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1448 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1460 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1470 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | T.getAsOpaquePtr(), RParenLoc); |
| 1472 | } |
| 1473 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 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 | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1479 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | SourceRange QualifierRange, |
| 1481 | DeclarationName Name, |
| 1482 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1483 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | CXXScopeSpec SS; |
| 1485 | SS.setRange(QualifierRange); |
| 1486 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 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 | a16548e | 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 | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1499 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1500 | LookupResult &R, |
| 1501 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1502 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1503 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 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 | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1511 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | CXXConstructorDecl *Constructor, |
| 1513 | bool IsElidable, |
| 1514 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 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 | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Douglas Gregor | a16548e | 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 | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1565 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1566 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1567 | bool IsArrow, |
| 1568 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1569 | NestedNameSpecifier *Qualifier, |
| 1570 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1571 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1572 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1573 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1574 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1575 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1576 | SS.setRange(QualifierRange); |
| 1577 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1579 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1580 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1581 | SS, FirstQualifierInScope, |
| 1582 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1585 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 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 | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1589 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1590 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1591 | SourceLocation OperatorLoc, |
| 1592 | bool IsArrow, |
| 1593 | NestedNameSpecifier *Qualifier, |
| 1594 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1595 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1596 | LookupResult &R, |
| 1597 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1598 | CXXScopeSpec SS; |
| 1599 | SS.setRange(QualifierRange); |
| 1600 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1602 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1603 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1604 | SS, FirstQualifierInScope, |
| 1605 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1606 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | } |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1654 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1656 | |
| 1657 | // Build the CallExpr |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1672 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1674 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | ebe1010 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1681 | switch (S->getStmtClass()) { |
| 1682 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1683 | |
Douglas Gregor | ebe1010 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1690 | // Transform expressions by calling TransformExpr. |
| 1691 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1692 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1699 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1700 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1704 | return SemaRef.Owned(S->Retain()); |
| 1705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1706 | |
| 1707 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1708 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1709 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 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 | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1716 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1717 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1718 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1719 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1722 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1726 | NestedNameSpecifier * |
| 1727 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1728 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1729 | QualType ObjectType, |
| 1730 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1731 | if (!NNS) |
| 1732 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1734 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1735 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1736 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1738 | ObjectType, |
| 1739 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1740 | if (!Prefix) |
| 1741 | return 0; |
Mike Stump | 11289f4 | 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 | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1744 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1745 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1746 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1749 | switch (NNS->getKind()) { |
| 1750 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 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 | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1755 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
| 1757 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1758 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1759 | ObjectType, |
| 1760 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1762 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1764 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1765 | getDerived().TransformDecl(Range.getBegin(), |
| 1766 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1768 | Prefix == NNS->getPrefix() && |
| 1769 | NS == NNS->getAsNamespace()) |
| 1770 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1772 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1775 | case NestedNameSpecifier::Global: |
| 1776 | // There is no meaningful transformation that one could perform on the |
| 1777 | // global scope. |
| 1778 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1779 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1780 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1781 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1782 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1783 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1784 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1785 | if (T.isNull()) |
| 1786 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1787 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1788 | if (!getDerived().AlwaysRebuild() && |
| 1789 | Prefix == NNS->getPrefix() && |
| 1790 | T == QualType(NNS->getAsType(), 0)) |
| 1791 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | |
| 1793 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1794 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1795 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1796 | } |
| 1797 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1799 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1800 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1805 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1806 | SourceLocation Loc, |
| 1807 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1808 | if (!Name) |
| 1809 | return Name; |
| 1810 | |
| 1811 | switch (Name.getNameKind()) { |
| 1812 | case DeclarationName::Identifier: |
| 1813 | case DeclarationName::ObjCZeroArgSelector: |
| 1814 | case DeclarationName::ObjCOneArgSelector: |
| 1815 | case DeclarationName::ObjCMultiArgSelector: |
| 1816 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1817 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1818 | case DeclarationName::CXXUsingDirective: |
| 1819 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1820 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1821 | case DeclarationName::CXXConstructorName: |
| 1822 | case DeclarationName::CXXDestructorName: |
| 1823 | case DeclarationName::CXXConversionFunctionName: { |
| 1824 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1825 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1826 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1827 | if (T.isNull()) |
| 1828 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1830 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1832 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1836 | return DeclarationName(); |
| 1837 | } |
| 1838 | |
| 1839 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1841 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1842 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1843 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1844 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1845 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1846 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1847 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1848 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1849 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | if (!NNS) |
| 1851 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1855 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1856 | if (!TransTemplate) |
| 1857 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1859 | if (!getDerived().AlwaysRebuild() && |
| 1860 | NNS == QTN->getQualifier() && |
| 1861 | TransTemplate == Template) |
| 1862 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1864 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1865 | TransTemplate); |
| 1866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1868 | // These should be getting filtered out before they make it into the AST. |
| 1869 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1872 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1875 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1876 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1877 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1880 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1881 | NNS == DTN->getQualifier() && |
| 1882 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1883 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1884 | |
Douglas Gregor | 71395fa | 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 | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1891 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1893 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1895 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1896 | if (!TransTemplate) |
| 1897 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1899 | if (!getDerived().AlwaysRebuild() && |
| 1900 | TransTemplate == Template) |
| 1901 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1902 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1903 | return TemplateName(TransTemplate); |
| 1904 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1905 | |
John McCall | e66edc1 | 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 | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | template<typename Derived> |
John McCall | 0ad1666 | 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 | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1918 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | |
| 1921 | case TemplateArgument::Type: |
| 1922 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1923 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1924 | |
| 1925 | break; |
| 1926 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1927 | case TemplateArgument::Template: |
| 1928 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1929 | break; |
| 1930 | |
John McCall | 0ad1666 | 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 | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1938 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 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 | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1948 | switch (Arg.getKind()) { |
| 1949 | case TemplateArgument::Null: |
| 1950 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1951 | Output = Input; |
| 1952 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1954 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1955 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1956 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1957 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 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 | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1964 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1966 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1967 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 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 | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1971 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1972 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1973 | if (!D) return true; |
| 1974 | |
John McCall | 0d07eb3 | 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 | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1989 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1990 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1991 | |
Douglas Gregor | 9167f8b | 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 | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2005 | case TemplateArgument::Expression: { |
| 2006 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2008 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
John McCall | 0ad1666 | 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 | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2018 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2019 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2020 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | |
Douglas Gregor | e922c77 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2026 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2027 | AEnd = Arg.pack_end(); |
| 2028 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
John McCall | 0ad1666 | 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 | 0d07eb3 | 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 | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2037 | return true; |
| 2038 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2039 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2040 | } |
| 2041 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2042 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2043 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2044 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2045 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2046 | } |
| 2047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2049 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2050 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2053 | //===----------------------------------------------------------------------===// |
| 2054 | // Type transformation |
| 2055 | //===----------------------------------------------------------------------===// |
| 2056 | |
| 2057 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2058 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2059 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2060 | if (getDerived().AlreadyTransformed(T)) |
| 2061 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2063 | // Temporary workaround. All of these transformations should |
| 2064 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2065 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2066 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2068 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2069 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2070 | if (!NewDI) |
| 2071 | return QualType(); |
| 2072 | |
| 2073 | return NewDI->getType(); |
| 2074 | } |
| 2075 | |
| 2076 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2077 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2078 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2079 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2080 | return DI; |
| 2081 | |
| 2082 | TypeLocBuilder TLB; |
| 2083 | |
| 2084 | TypeLoc TL = DI->getTypeLoc(); |
| 2085 | TLB.reserve(TL.getFullDataSize()); |
| 2086 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2087 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2088 | if (Result.isNull()) |
| 2089 | return 0; |
| 2090 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2091 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | template<typename Derived> |
| 2095 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2096 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2097 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2098 | switch (T.getTypeLocClass()) { |
| 2099 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2100 | #define TYPELOC(CLASS, PARENT) \ |
| 2101 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2102 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2103 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2104 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2105 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2106 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2107 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2108 | return QualType(); |
| 2109 | } |
| 2110 | |
| 2111 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2112 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2113 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2114 | /// types). This is the right thing for template instantiation, but |
| 2115 | /// probably not for other clients. |
| 2116 | template<typename Derived> |
| 2117 | QualType |
| 2118 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2119 | QualifiedTypeLoc T, |
| 2120 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2121 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2122 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2123 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2124 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2125 | if (Result.isNull()) |
| 2126 | return QualType(); |
| 2127 | |
| 2128 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2129 | // FIXME: this is the right thing for template instantiation, but |
| 2130 | // probably not for other clients. |
| 2131 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2132 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2133 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2134 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2135 | |
| 2136 | TLB.push<QualifiedTypeLoc>(Result); |
| 2137 | |
| 2138 | // No location information to preserve. |
| 2139 | |
| 2140 | return Result; |
| 2141 | } |
| 2142 | |
| 2143 | template <class TyLoc> static inline |
| 2144 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2145 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2146 | NewT.setNameLoc(T.getNameLoc()); |
| 2147 | return T.getType(); |
| 2148 | } |
| 2149 | |
| 2150 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2151 | // the equivalent template version work. |
| 2152 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2153 | QualType PointeeType \ |
| 2154 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2155 | if (PointeeType.isNull()) \ |
| 2156 | return QualType(); \ |
| 2157 | \ |
| 2158 | QualType Result = TL.getType(); \ |
| 2159 | if (getDerived().AlwaysRebuild() || \ |
| 2160 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2161 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2162 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2163 | if (Result.isNull()) \ |
| 2164 | return QualType(); \ |
| 2165 | } \ |
| 2166 | \ |
| 2167 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2168 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2169 | \ |
| 2170 | return Result; \ |
| 2171 | } while(0) |
| 2172 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2173 | template<typename Derived> |
| 2174 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2175 | BuiltinTypeLoc T, |
| 2176 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2177 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2178 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2179 | if (T.needsExtraLocalData()) |
| 2180 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2181 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2184 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2185 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2186 | ComplexTypeLoc T, |
| 2187 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2188 | // FIXME: recurse? |
| 2189 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2192 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2193 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2194 | PointerTypeLoc TL, |
| 2195 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2196 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
| 2199 | template<typename Derived> |
| 2200 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2201 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2202 | BlockPointerTypeLoc TL, |
| 2203 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2204 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2207 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2208 | /// don't care whether the type itself is an l-value type or an r-value |
| 2209 | /// type; we only care if the type was *written* as an l-value type |
| 2210 | /// or an r-value type. |
| 2211 | template<typename Derived> |
| 2212 | QualType |
| 2213 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2214 | ReferenceTypeLoc TL, |
| 2215 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2216 | const ReferenceType *T = TL.getTypePtr(); |
| 2217 | |
| 2218 | // Note that this works with the pointee-as-written. |
| 2219 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2220 | if (PointeeType.isNull()) |
| 2221 | return QualType(); |
| 2222 | |
| 2223 | QualType Result = TL.getType(); |
| 2224 | if (getDerived().AlwaysRebuild() || |
| 2225 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2226 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2227 | T->isSpelledAsLValue(), |
| 2228 | TL.getSigilLoc()); |
| 2229 | if (Result.isNull()) |
| 2230 | return QualType(); |
| 2231 | } |
| 2232 | |
| 2233 | // r-value references can be rebuilt as l-value references. |
| 2234 | ReferenceTypeLoc NewTL; |
| 2235 | if (isa<LValueReferenceType>(Result)) |
| 2236 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2237 | else |
| 2238 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2239 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2240 | |
| 2241 | return Result; |
| 2242 | } |
| 2243 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2244 | template<typename Derived> |
| 2245 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2246 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2247 | LValueReferenceTypeLoc TL, |
| 2248 | QualType ObjectType) { |
| 2249 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | template<typename Derived> |
| 2253 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2254 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2255 | RValueReferenceTypeLoc TL, |
| 2256 | QualType ObjectType) { |
| 2257 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2258 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2259 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2260 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2261 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2262 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2263 | MemberPointerTypeLoc TL, |
| 2264 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2265 | MemberPointerType *T = TL.getTypePtr(); |
| 2266 | |
| 2267 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2268 | if (PointeeType.isNull()) |
| 2269 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2270 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2271 | // TODO: preserve source information for this. |
| 2272 | QualType ClassType |
| 2273 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2274 | if (ClassType.isNull()) |
| 2275 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2277 | QualType Result = TL.getType(); |
| 2278 | if (getDerived().AlwaysRebuild() || |
| 2279 | PointeeType != T->getPointeeType() || |
| 2280 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2281 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2282 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2283 | if (Result.isNull()) |
| 2284 | return QualType(); |
| 2285 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2286 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2287 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2288 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2289 | |
| 2290 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2293 | template<typename Derived> |
| 2294 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2295 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2296 | ConstantArrayTypeLoc TL, |
| 2297 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2298 | ConstantArrayType *T = TL.getTypePtr(); |
| 2299 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2300 | if (ElementType.isNull()) |
| 2301 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2302 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2303 | QualType Result = TL.getType(); |
| 2304 | if (getDerived().AlwaysRebuild() || |
| 2305 | ElementType != T->getElementType()) { |
| 2306 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2307 | T->getSizeModifier(), |
| 2308 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2309 | T->getIndexTypeCVRQualifiers(), |
| 2310 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2311 | if (Result.isNull()) |
| 2312 | return QualType(); |
| 2313 | } |
| 2314 | |
| 2315 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2316 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2317 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2318 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2319 | Expr *Size = TL.getSizeExpr(); |
| 2320 | if (Size) { |
| 2321 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2322 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2323 | } |
| 2324 | NewTL.setSizeExpr(Size); |
| 2325 | |
| 2326 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2327 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2328 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2329 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2330 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2331 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2332 | IncompleteArrayTypeLoc TL, |
| 2333 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2334 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2335 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2336 | if (ElementType.isNull()) |
| 2337 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2338 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2339 | QualType Result = TL.getType(); |
| 2340 | if (getDerived().AlwaysRebuild() || |
| 2341 | ElementType != T->getElementType()) { |
| 2342 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2343 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2344 | T->getIndexTypeCVRQualifiers(), |
| 2345 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2346 | if (Result.isNull()) |
| 2347 | return QualType(); |
| 2348 | } |
| 2349 | |
| 2350 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2351 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2352 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2353 | NewTL.setSizeExpr(0); |
| 2354 | |
| 2355 | return Result; |
| 2356 | } |
| 2357 | |
| 2358 | template<typename Derived> |
| 2359 | QualType |
| 2360 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2361 | VariableArrayTypeLoc TL, |
| 2362 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2363 | VariableArrayType *T = TL.getTypePtr(); |
| 2364 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2365 | if (ElementType.isNull()) |
| 2366 | return QualType(); |
| 2367 | |
| 2368 | // Array bounds are not potentially evaluated contexts |
| 2369 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2370 | |
| 2371 | Sema::OwningExprResult SizeResult |
| 2372 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2373 | if (SizeResult.isInvalid()) |
| 2374 | return QualType(); |
| 2375 | |
| 2376 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2377 | |
| 2378 | QualType Result = TL.getType(); |
| 2379 | if (getDerived().AlwaysRebuild() || |
| 2380 | ElementType != T->getElementType() || |
| 2381 | Size != T->getSizeExpr()) { |
| 2382 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2383 | T->getSizeModifier(), |
| 2384 | move(SizeResult), |
| 2385 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2386 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2387 | if (Result.isNull()) |
| 2388 | return QualType(); |
| 2389 | } |
| 2390 | else SizeResult.take(); |
| 2391 | |
| 2392 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2393 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2394 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2395 | NewTL.setSizeExpr(Size); |
| 2396 | |
| 2397 | return Result; |
| 2398 | } |
| 2399 | |
| 2400 | template<typename Derived> |
| 2401 | QualType |
| 2402 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2403 | DependentSizedArrayTypeLoc TL, |
| 2404 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2405 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2406 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2407 | if (ElementType.isNull()) |
| 2408 | return QualType(); |
| 2409 | |
| 2410 | // Array bounds are not potentially evaluated contexts |
| 2411 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2412 | |
| 2413 | Sema::OwningExprResult SizeResult |
| 2414 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2415 | if (SizeResult.isInvalid()) |
| 2416 | return QualType(); |
| 2417 | |
| 2418 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2419 | |
| 2420 | QualType Result = TL.getType(); |
| 2421 | if (getDerived().AlwaysRebuild() || |
| 2422 | ElementType != T->getElementType() || |
| 2423 | Size != T->getSizeExpr()) { |
| 2424 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2425 | T->getSizeModifier(), |
| 2426 | move(SizeResult), |
| 2427 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2428 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2429 | if (Result.isNull()) |
| 2430 | return QualType(); |
| 2431 | } |
| 2432 | else SizeResult.take(); |
| 2433 | |
| 2434 | // We might have any sort of array type now, but fortunately they |
| 2435 | // all have the same location layout. |
| 2436 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2437 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2438 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2439 | NewTL.setSizeExpr(Size); |
| 2440 | |
| 2441 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2442 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
| 2444 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2445 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2446 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2447 | DependentSizedExtVectorTypeLoc TL, |
| 2448 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2449 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2450 | |
| 2451 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2452 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2453 | if (ElementType.isNull()) |
| 2454 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2455 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2456 | // Vector sizes are not potentially evaluated contexts |
| 2457 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2458 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2459 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2460 | if (Size.isInvalid()) |
| 2461 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2462 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | QualType Result = TL.getType(); |
| 2464 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2465 | ElementType != T->getElementType() || |
| 2466 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2467 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2468 | move(Size), |
| 2469 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2470 | if (Result.isNull()) |
| 2471 | return QualType(); |
| 2472 | } |
| 2473 | else Size.take(); |
| 2474 | |
| 2475 | // Result might be dependent or not. |
| 2476 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2477 | DependentSizedExtVectorTypeLoc NewTL |
| 2478 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2479 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2480 | } else { |
| 2481 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2482 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2483 | } |
| 2484 | |
| 2485 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2487 | |
| 2488 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2489 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2490 | VectorTypeLoc TL, |
| 2491 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2492 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2493 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2494 | if (ElementType.isNull()) |
| 2495 | return QualType(); |
| 2496 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | QualType Result = TL.getType(); |
| 2498 | if (getDerived().AlwaysRebuild() || |
| 2499 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2500 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2501 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2502 | if (Result.isNull()) |
| 2503 | return QualType(); |
| 2504 | } |
| 2505 | |
| 2506 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2507 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2508 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2509 | return Result; |
| 2510 | } |
| 2511 | |
| 2512 | template<typename Derived> |
| 2513 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2514 | ExtVectorTypeLoc TL, |
| 2515 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2516 | VectorType *T = TL.getTypePtr(); |
| 2517 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2518 | if (ElementType.isNull()) |
| 2519 | return QualType(); |
| 2520 | |
| 2521 | QualType Result = TL.getType(); |
| 2522 | if (getDerived().AlwaysRebuild() || |
| 2523 | ElementType != T->getElementType()) { |
| 2524 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2525 | T->getNumElements(), |
| 2526 | /*FIXME*/ SourceLocation()); |
| 2527 | if (Result.isNull()) |
| 2528 | return QualType(); |
| 2529 | } |
| 2530 | |
| 2531 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2532 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2533 | |
| 2534 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2535 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2536 | |
| 2537 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame^] | 2538 | ParmVarDecl * |
| 2539 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2540 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2541 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2542 | if (!NewDI) |
| 2543 | return 0; |
| 2544 | |
| 2545 | if (NewDI == OldDI) |
| 2546 | return OldParm; |
| 2547 | else |
| 2548 | return ParmVarDecl::Create(SemaRef.Context, |
| 2549 | OldParm->getDeclContext(), |
| 2550 | OldParm->getLocation(), |
| 2551 | OldParm->getIdentifier(), |
| 2552 | NewDI->getType(), |
| 2553 | NewDI, |
| 2554 | OldParm->getStorageClass(), |
| 2555 | /* DefArg */ NULL); |
| 2556 | } |
| 2557 | |
| 2558 | template<typename Derived> |
| 2559 | bool TreeTransform<Derived>:: |
| 2560 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2561 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2562 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2563 | FunctionProtoType *T = TL.getTypePtr(); |
| 2564 | |
| 2565 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2566 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2567 | |
| 2568 | QualType NewType; |
| 2569 | ParmVarDecl *NewParm; |
| 2570 | |
| 2571 | if (OldParm) { |
| 2572 | assert(OldParm->getTypeSourceInfo()->getType() == T->getArgType(i)); |
| 2573 | |
| 2574 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2575 | if (!NewParm) |
| 2576 | return true; |
| 2577 | NewType = NewParm->getType(); |
| 2578 | |
| 2579 | // Deal with the possibility that we don't have a parameter |
| 2580 | // declaration for this parameter. |
| 2581 | } else { |
| 2582 | NewParm = 0; |
| 2583 | |
| 2584 | QualType OldType = T->getArgType(i); |
| 2585 | NewType = getDerived().TransformType(OldType); |
| 2586 | if (NewType.isNull()) |
| 2587 | return true; |
| 2588 | } |
| 2589 | |
| 2590 | PTypes.push_back(NewType); |
| 2591 | PVars.push_back(NewParm); |
| 2592 | } |
| 2593 | |
| 2594 | return false; |
| 2595 | } |
| 2596 | |
| 2597 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2598 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2599 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2600 | FunctionProtoTypeLoc TL, |
| 2601 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2602 | FunctionProtoType *T = TL.getTypePtr(); |
| 2603 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2604 | if (ResultType.isNull()) |
| 2605 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2606 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2607 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2608 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2609 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame^] | 2610 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2611 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2612 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2613 | QualType Result = TL.getType(); |
| 2614 | if (getDerived().AlwaysRebuild() || |
| 2615 | ResultType != T->getResultType() || |
| 2616 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2617 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2618 | ParamTypes.data(), |
| 2619 | ParamTypes.size(), |
| 2620 | T->isVariadic(), |
| 2621 | T->getTypeQuals()); |
| 2622 | if (Result.isNull()) |
| 2623 | return QualType(); |
| 2624 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2625 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2626 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2627 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2628 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2629 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2630 | NewTL.setArg(i, ParamDecls[i]); |
| 2631 | |
| 2632 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2633 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2635 | template<typename Derived> |
| 2636 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2637 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2638 | FunctionNoProtoTypeLoc TL, |
| 2639 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2640 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2641 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2642 | if (ResultType.isNull()) |
| 2643 | return QualType(); |
| 2644 | |
| 2645 | QualType Result = TL.getType(); |
| 2646 | if (getDerived().AlwaysRebuild() || |
| 2647 | ResultType != T->getResultType()) |
| 2648 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2649 | |
| 2650 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2651 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2652 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2653 | |
| 2654 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2657 | template<typename Derived> QualType |
| 2658 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2659 | UnresolvedUsingTypeLoc TL, |
| 2660 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2661 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2662 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2663 | if (!D) |
| 2664 | return QualType(); |
| 2665 | |
| 2666 | QualType Result = TL.getType(); |
| 2667 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2668 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2669 | if (Result.isNull()) |
| 2670 | return QualType(); |
| 2671 | } |
| 2672 | |
| 2673 | // We might get an arbitrary type spec type back. We should at |
| 2674 | // least always get a type spec type, though. |
| 2675 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2676 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2677 | |
| 2678 | return Result; |
| 2679 | } |
| 2680 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2681 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2682 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2683 | TypedefTypeLoc TL, |
| 2684 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2685 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2686 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2687 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2688 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2689 | if (!Typedef) |
| 2690 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2692 | QualType Result = TL.getType(); |
| 2693 | if (getDerived().AlwaysRebuild() || |
| 2694 | Typedef != T->getDecl()) { |
| 2695 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2696 | if (Result.isNull()) |
| 2697 | return QualType(); |
| 2698 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2699 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2700 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2701 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2702 | |
| 2703 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2705 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2706 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2707 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2708 | TypeOfExprTypeLoc TL, |
| 2709 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2710 | // typeof expressions are not potentially evaluated contexts |
| 2711 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2712 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2713 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2714 | if (E.isInvalid()) |
| 2715 | return QualType(); |
| 2716 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2717 | QualType Result = TL.getType(); |
| 2718 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2719 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2720 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2721 | if (Result.isNull()) |
| 2722 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2723 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2724 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2727 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2728 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2729 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2730 | |
| 2731 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2733 | |
| 2734 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2735 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2736 | TypeOfTypeLoc TL, |
| 2737 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2738 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2739 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2740 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2741 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2743 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2744 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2745 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2746 | if (Result.isNull()) |
| 2747 | return QualType(); |
| 2748 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2749 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2751 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2752 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2753 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2754 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2755 | |
| 2756 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2757 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2758 | |
| 2759 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2760 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2761 | DecltypeTypeLoc TL, |
| 2762 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2763 | DecltypeType *T = TL.getTypePtr(); |
| 2764 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2765 | // decltype expressions are not potentially evaluated contexts |
| 2766 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2767 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2768 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2769 | if (E.isInvalid()) |
| 2770 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2771 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2772 | QualType Result = TL.getType(); |
| 2773 | if (getDerived().AlwaysRebuild() || |
| 2774 | E.get() != T->getUnderlyingExpr()) { |
| 2775 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2776 | if (Result.isNull()) |
| 2777 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2778 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2779 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2780 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2781 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2782 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2783 | |
| 2784 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2788 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2789 | RecordTypeLoc TL, |
| 2790 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2791 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2792 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2793 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2794 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2795 | if (!Record) |
| 2796 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2797 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2798 | QualType Result = TL.getType(); |
| 2799 | if (getDerived().AlwaysRebuild() || |
| 2800 | Record != T->getDecl()) { |
| 2801 | Result = getDerived().RebuildRecordType(Record); |
| 2802 | if (Result.isNull()) |
| 2803 | return QualType(); |
| 2804 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2805 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2806 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2807 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2808 | |
| 2809 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | |
| 2812 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2813 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2814 | EnumTypeLoc TL, |
| 2815 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2816 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2817 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2818 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2819 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | if (!Enum) |
| 2821 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2822 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2823 | QualType Result = TL.getType(); |
| 2824 | if (getDerived().AlwaysRebuild() || |
| 2825 | Enum != T->getDecl()) { |
| 2826 | Result = getDerived().RebuildEnumType(Enum); |
| 2827 | if (Result.isNull()) |
| 2828 | return QualType(); |
| 2829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2830 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2831 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2832 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2833 | |
| 2834 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2835 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2836 | |
| 2837 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2838 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2839 | ElaboratedTypeLoc TL, |
| 2840 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2841 | ElaboratedType *T = TL.getTypePtr(); |
| 2842 | |
| 2843 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2844 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2845 | if (Underlying.isNull()) |
| 2846 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2847 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2848 | QualType Result = TL.getType(); |
| 2849 | if (getDerived().AlwaysRebuild() || |
| 2850 | Underlying != T->getUnderlyingType()) { |
| 2851 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2852 | if (Result.isNull()) |
| 2853 | return QualType(); |
| 2854 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2855 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2856 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2857 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2858 | |
| 2859 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2860 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2861 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2862 | template<typename Derived> |
| 2863 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 2864 | TypeLocBuilder &TLB, |
| 2865 | InjectedClassNameTypeLoc TL, |
| 2866 | QualType ObjectType) { |
| 2867 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 2868 | TL.getTypePtr()->getDecl()); |
| 2869 | if (!D) return QualType(); |
| 2870 | |
| 2871 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 2872 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 2873 | return T; |
| 2874 | } |
| 2875 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2876 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2877 | template<typename Derived> |
| 2878 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2879 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2880 | TemplateTypeParmTypeLoc TL, |
| 2881 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2882 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2885 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2886 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2887 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2888 | SubstTemplateTypeParmTypeLoc TL, |
| 2889 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2890 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2894 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2895 | const TemplateSpecializationType *TST, |
| 2896 | QualType ObjectType) { |
| 2897 | // FIXME: this entire method is a temporary workaround; callers |
| 2898 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2899 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2900 | // Fake up a TemplateSpecializationTypeLoc. |
| 2901 | TypeLocBuilder TLB; |
| 2902 | TemplateSpecializationTypeLoc TL |
| 2903 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2904 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2905 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2906 | |
| 2907 | TL.setTemplateNameLoc(BaseLoc); |
| 2908 | TL.setLAngleLoc(BaseLoc); |
| 2909 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2910 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2911 | const TemplateArgument &TA = TST->getArg(i); |
| 2912 | TemplateArgumentLoc TAL; |
| 2913 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2914 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2915 | } |
| 2916 | |
| 2917 | TypeLocBuilder IgnoredTLB; |
| 2918 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2922 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2923 | TypeLocBuilder &TLB, |
| 2924 | TemplateSpecializationTypeLoc TL, |
| 2925 | QualType ObjectType) { |
| 2926 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2927 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2928 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2929 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2930 | if (Template.isNull()) |
| 2931 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2932 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2933 | TemplateArgumentListInfo NewTemplateArgs; |
| 2934 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2935 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2936 | |
| 2937 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2938 | TemplateArgumentLoc Loc; |
| 2939 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2940 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2941 | NewTemplateArgs.addArgument(Loc); |
| 2942 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2944 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2945 | |
| 2946 | QualType Result = |
| 2947 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2948 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2949 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2950 | |
| 2951 | if (!Result.isNull()) { |
| 2952 | TemplateSpecializationTypeLoc NewTL |
| 2953 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2954 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2955 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2956 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2957 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2958 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2959 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2960 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2961 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2962 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2963 | |
| 2964 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2965 | QualType |
| 2966 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2967 | QualifiedNameTypeLoc TL, |
| 2968 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2969 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2970 | NestedNameSpecifier *NNS |
| 2971 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2972 | SourceRange(), |
| 2973 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2974 | if (!NNS) |
| 2975 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2976 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2977 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2978 | if (Named.isNull()) |
| 2979 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2980 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2981 | QualType Result = TL.getType(); |
| 2982 | if (getDerived().AlwaysRebuild() || |
| 2983 | NNS != T->getQualifier() || |
| 2984 | Named != T->getNamedType()) { |
| 2985 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2986 | if (Result.isNull()) |
| 2987 | return QualType(); |
| 2988 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2989 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2990 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2991 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2992 | |
| 2993 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2994 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | |
| 2996 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2997 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2998 | TypenameTypeLoc TL, |
| 2999 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3000 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3001 | |
| 3002 | /* FIXME: preserve source information better than this */ |
| 3003 | SourceRange SR(TL.getNameLoc()); |
| 3004 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3005 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3006 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3007 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3008 | if (!NNS) |
| 3009 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3010 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3011 | QualType Result; |
| 3012 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3013 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3014 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3015 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3016 | if (NewTemplateId.isNull()) |
| 3017 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3019 | if (!getDerived().AlwaysRebuild() && |
| 3020 | NNS == T->getQualifier() && |
| 3021 | NewTemplateId == QualType(TemplateId, 0)) |
| 3022 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3023 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3024 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 3025 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3026 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3027 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3028 | if (Result.isNull()) |
| 3029 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3030 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3031 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 3032 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3033 | |
| 3034 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3037 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3038 | QualType |
| 3039 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3040 | ObjCInterfaceTypeLoc TL, |
| 3041 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3042 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 3043 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3044 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
| 3046 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3047 | QualType |
| 3048 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3049 | ObjCObjectPointerTypeLoc TL, |
| 3050 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3051 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3052 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3055 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3056 | // Statement transformation |
| 3057 | //===----------------------------------------------------------------------===// |
| 3058 | template<typename Derived> |
| 3059 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3060 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3061 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | template<typename Derived> |
| 3065 | Sema::OwningStmtResult |
| 3066 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3067 | return getDerived().TransformCompoundStmt(S, false); |
| 3068 | } |
| 3069 | |
| 3070 | template<typename Derived> |
| 3071 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3072 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3073 | bool IsStmtExpr) { |
| 3074 | bool SubStmtChanged = false; |
| 3075 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3076 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3077 | B != BEnd; ++B) { |
| 3078 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3079 | if (Result.isInvalid()) |
| 3080 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3082 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3083 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3086 | if (!getDerived().AlwaysRebuild() && |
| 3087 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3089 | |
| 3090 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3091 | move_arg(Statements), |
| 3092 | S->getRBracLoc(), |
| 3093 | IsStmtExpr); |
| 3094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3095 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3096 | template<typename Derived> |
| 3097 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3099 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3100 | { |
| 3101 | // The case value expressions are not potentially evaluated. |
| 3102 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3104 | // Transform the left-hand case value. |
| 3105 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3106 | if (LHS.isInvalid()) |
| 3107 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3108 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3109 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3110 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3111 | if (RHS.isInvalid()) |
| 3112 | return SemaRef.StmtError(); |
| 3113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3115 | // Build the case statement. |
| 3116 | // Case statements are always rebuilt so that they will attached to their |
| 3117 | // transformed switch statement. |
| 3118 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3119 | move(LHS), |
| 3120 | S->getEllipsisLoc(), |
| 3121 | move(RHS), |
| 3122 | S->getColonLoc()); |
| 3123 | if (Case.isInvalid()) |
| 3124 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3126 | // Transform the statement following the case |
| 3127 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3128 | if (SubStmt.isInvalid()) |
| 3129 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3130 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3131 | // Attach the body to the case statement |
| 3132 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3133 | } |
| 3134 | |
| 3135 | template<typename Derived> |
| 3136 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3138 | // Transform the statement following the default case |
| 3139 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3140 | if (SubStmt.isInvalid()) |
| 3141 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3142 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3143 | // Default statements are always rebuilt |
| 3144 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3145 | move(SubStmt)); |
| 3146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3147 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3148 | template<typename Derived> |
| 3149 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3150 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3151 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3152 | if (SubStmt.isInvalid()) |
| 3153 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3155 | // FIXME: Pass the real colon location in. |
| 3156 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3157 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3158 | move(SubStmt)); |
| 3159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3160 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3161 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | Sema::OwningStmtResult |
| 3163 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3164 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3165 | OwningExprResult Cond(SemaRef); |
| 3166 | VarDecl *ConditionVar = 0; |
| 3167 | if (S->getConditionVariable()) { |
| 3168 | ConditionVar |
| 3169 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3170 | getDerived().TransformDefinition( |
| 3171 | S->getConditionVariable()->getLocation(), |
| 3172 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3173 | if (!ConditionVar) |
| 3174 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3175 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3176 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3177 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3178 | if (Cond.isInvalid()) |
| 3179 | return SemaRef.StmtError(); |
| 3180 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3181 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3182 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3183 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3184 | // Transform the "then" branch. |
| 3185 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3186 | if (Then.isInvalid()) |
| 3187 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3189 | // Transform the "else" branch. |
| 3190 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3191 | if (Else.isInvalid()) |
| 3192 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3193 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3194 | if (!getDerived().AlwaysRebuild() && |
| 3195 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3196 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3197 | Then.get() == S->getThen() && |
| 3198 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3199 | return SemaRef.Owned(S->Retain()); |
| 3200 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3201 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3202 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | template<typename Derived> |
| 3207 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3208 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3209 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3210 | OwningExprResult Cond(SemaRef); |
| 3211 | VarDecl *ConditionVar = 0; |
| 3212 | if (S->getConditionVariable()) { |
| 3213 | ConditionVar |
| 3214 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3215 | getDerived().TransformDefinition( |
| 3216 | S->getConditionVariable()->getLocation(), |
| 3217 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3218 | if (!ConditionVar) |
| 3219 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3220 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3221 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3222 | |
| 3223 | if (Cond.isInvalid()) |
| 3224 | return SemaRef.StmtError(); |
| 3225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3226 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3227 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3228 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3229 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3230 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3231 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3232 | if (Switch.isInvalid()) |
| 3233 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | // Transform the body of the switch statement. |
| 3236 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3237 | if (Body.isInvalid()) |
| 3238 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3239 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3240 | // Complete the switch statement. |
| 3241 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3242 | move(Body)); |
| 3243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3245 | template<typename Derived> |
| 3246 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3247 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3248 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3249 | OwningExprResult Cond(SemaRef); |
| 3250 | VarDecl *ConditionVar = 0; |
| 3251 | if (S->getConditionVariable()) { |
| 3252 | ConditionVar |
| 3253 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3254 | getDerived().TransformDefinition( |
| 3255 | S->getConditionVariable()->getLocation(), |
| 3256 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3257 | if (!ConditionVar) |
| 3258 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3259 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3260 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3261 | |
| 3262 | if (Cond.isInvalid()) |
| 3263 | return SemaRef.StmtError(); |
| 3264 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3265 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3266 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3268 | // Transform the body |
| 3269 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3270 | if (Body.isInvalid()) |
| 3271 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3272 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3273 | if (!getDerived().AlwaysRebuild() && |
| 3274 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3275 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | return SemaRef.Owned(S->Retain()); |
| 3278 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3279 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3280 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3281 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | template<typename Derived> |
| 3284 | Sema::OwningStmtResult |
| 3285 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3286 | // Transform the condition |
| 3287 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3288 | if (Cond.isInvalid()) |
| 3289 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3291 | // Transform the body |
| 3292 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3293 | if (Body.isInvalid()) |
| 3294 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3296 | if (!getDerived().AlwaysRebuild() && |
| 3297 | Cond.get() == S->getCond() && |
| 3298 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | return SemaRef.Owned(S->Retain()); |
| 3300 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3301 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3302 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3303 | S->getRParenLoc()); |
| 3304 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3306 | template<typename Derived> |
| 3307 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | // Transform the initialization statement |
| 3310 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3311 | if (Init.isInvalid()) |
| 3312 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3315 | OwningExprResult Cond(SemaRef); |
| 3316 | VarDecl *ConditionVar = 0; |
| 3317 | if (S->getConditionVariable()) { |
| 3318 | ConditionVar |
| 3319 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3320 | getDerived().TransformDefinition( |
| 3321 | S->getConditionVariable()->getLocation(), |
| 3322 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3323 | if (!ConditionVar) |
| 3324 | return SemaRef.StmtError(); |
| 3325 | } else { |
| 3326 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3327 | |
| 3328 | if (Cond.isInvalid()) |
| 3329 | return SemaRef.StmtError(); |
| 3330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3331 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3332 | // Transform the increment |
| 3333 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3334 | if (Inc.isInvalid()) |
| 3335 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | // Transform the body |
| 3338 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3339 | if (Body.isInvalid()) |
| 3340 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | if (!getDerived().AlwaysRebuild() && |
| 3343 | Init.get() == S->getInit() && |
| 3344 | Cond.get() == S->getCond() && |
| 3345 | Inc.get() == S->getInc() && |
| 3346 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3347 | return SemaRef.Owned(S->Retain()); |
| 3348 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3350 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3351 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3352 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | S->getRParenLoc(), move(Body)); |
| 3354 | } |
| 3355 | |
| 3356 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | Sema::OwningStmtResult |
| 3358 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3360 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3361 | S->getLabel()); |
| 3362 | } |
| 3363 | |
| 3364 | template<typename Derived> |
| 3365 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3366 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3367 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3368 | if (Target.isInvalid()) |
| 3369 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3370 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3371 | if (!getDerived().AlwaysRebuild() && |
| 3372 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3373 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3374 | |
| 3375 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3376 | move(Target)); |
| 3377 | } |
| 3378 | |
| 3379 | template<typename Derived> |
| 3380 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3382 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3383 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3384 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3385 | template<typename Derived> |
| 3386 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3387 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3388 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3389 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3390 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3391 | template<typename Derived> |
| 3392 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3393 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3394 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3395 | if (Result.isInvalid()) |
| 3396 | return SemaRef.StmtError(); |
| 3397 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3398 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3399 | // to tell whether the return type of the function has changed. |
| 3400 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3402 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3403 | template<typename Derived> |
| 3404 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | bool DeclChanged = false; |
| 3407 | llvm::SmallVector<Decl *, 4> Decls; |
| 3408 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3409 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3410 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3411 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3412 | if (!Transformed) |
| 3413 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3414 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3415 | if (Transformed != *D) |
| 3416 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3418 | Decls.push_back(Transformed); |
| 3419 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3420 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3421 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | return SemaRef.Owned(S->Retain()); |
| 3423 | |
| 3424 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3425 | S->getStartLoc(), S->getEndLoc()); |
| 3426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3428 | template<typename Derived> |
| 3429 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3430 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3431 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | template<typename Derived> |
| 3436 | Sema::OwningStmtResult |
| 3437 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3438 | |
| 3439 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3440 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3441 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3442 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3443 | OwningExprResult AsmString(SemaRef); |
| 3444 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3445 | |
| 3446 | bool ExprsChanged = false; |
| 3447 | |
| 3448 | // Go through the outputs. |
| 3449 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3450 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3451 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3452 | // No need to transform the constraint literal. |
| 3453 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3454 | |
| 3455 | // Transform the output expr. |
| 3456 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3457 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3458 | if (Result.isInvalid()) |
| 3459 | return SemaRef.StmtError(); |
| 3460 | |
| 3461 | ExprsChanged |= Result.get() != OutputExpr; |
| 3462 | |
| 3463 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3464 | } |
| 3465 | |
| 3466 | // Go through the inputs. |
| 3467 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3468 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3469 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3470 | // No need to transform the constraint literal. |
| 3471 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3472 | |
| 3473 | // Transform the input expr. |
| 3474 | Expr *InputExpr = S->getInputExpr(I); |
| 3475 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3476 | if (Result.isInvalid()) |
| 3477 | return SemaRef.StmtError(); |
| 3478 | |
| 3479 | ExprsChanged |= Result.get() != InputExpr; |
| 3480 | |
| 3481 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3482 | } |
| 3483 | |
| 3484 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3485 | return SemaRef.Owned(S->Retain()); |
| 3486 | |
| 3487 | // Go through the clobbers. |
| 3488 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3489 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3490 | |
| 3491 | // No need to transform the asm string literal. |
| 3492 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3493 | |
| 3494 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3495 | S->isSimple(), |
| 3496 | S->isVolatile(), |
| 3497 | S->getNumOutputs(), |
| 3498 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3499 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3500 | move_arg(Constraints), |
| 3501 | move_arg(Exprs), |
| 3502 | move(AsmString), |
| 3503 | move_arg(Clobbers), |
| 3504 | S->getRParenLoc(), |
| 3505 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | |
| 3509 | template<typename Derived> |
| 3510 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3511 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3512 | // FIXME: Implement this |
| 3513 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3515 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3517 | template<typename Derived> |
| 3518 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3520 | // FIXME: Implement this |
| 3521 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3522 | return SemaRef.Owned(S->Retain()); |
| 3523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3524 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3525 | template<typename Derived> |
| 3526 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3528 | // FIXME: Implement this |
| 3529 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3533 | template<typename Derived> |
| 3534 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | // FIXME: Implement this |
| 3537 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3538 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3539 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3541 | template<typename Derived> |
| 3542 | Sema::OwningStmtResult |
| 3543 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | // FIXME: Implement this |
| 3546 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3547 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | template<typename Derived> |
| 3551 | Sema::OwningStmtResult |
| 3552 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3554 | // FIXME: Implement this |
| 3555 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3556 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | |
| 3560 | template<typename Derived> |
| 3561 | Sema::OwningStmtResult |
| 3562 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3563 | // Transform the exception declaration, if any. |
| 3564 | VarDecl *Var = 0; |
| 3565 | if (S->getExceptionDecl()) { |
| 3566 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3567 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3568 | ExceptionDecl->getDeclName()); |
| 3569 | |
| 3570 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3571 | if (T.isNull()) |
| 3572 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3574 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3575 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3576 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3577 | ExceptionDecl->getIdentifier(), |
| 3578 | ExceptionDecl->getLocation(), |
| 3579 | /*FIXME: Inaccurate*/ |
| 3580 | SourceRange(ExceptionDecl->getLocation())); |
| 3581 | if (!Var || Var->isInvalidDecl()) { |
| 3582 | if (Var) |
| 3583 | Var->Destroy(SemaRef.Context); |
| 3584 | return SemaRef.StmtError(); |
| 3585 | } |
| 3586 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3587 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3588 | // Transform the actual exception handler. |
| 3589 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3590 | if (Handler.isInvalid()) { |
| 3591 | if (Var) |
| 3592 | Var->Destroy(SemaRef.Context); |
| 3593 | return SemaRef.StmtError(); |
| 3594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3595 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3596 | if (!getDerived().AlwaysRebuild() && |
| 3597 | !Var && |
| 3598 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3600 | |
| 3601 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3602 | Var, |
| 3603 | move(Handler)); |
| 3604 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3606 | template<typename Derived> |
| 3607 | Sema::OwningStmtResult |
| 3608 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3609 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3611 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3612 | if (TryBlock.isInvalid()) |
| 3613 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3615 | // Transform the handlers. |
| 3616 | bool HandlerChanged = false; |
| 3617 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3618 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3619 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3620 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3621 | if (Handler.isInvalid()) |
| 3622 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3623 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3624 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3625 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3626 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3628 | if (!getDerived().AlwaysRebuild() && |
| 3629 | TryBlock.get() == S->getTryBlock() && |
| 3630 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3632 | |
| 3633 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3634 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3636 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3637 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3638 | // Expression transformation |
| 3639 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 | template<typename Derived> |
| 3641 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3642 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
| 3646 | template<typename Derived> |
| 3647 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3648 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3649 | NestedNameSpecifier *Qualifier = 0; |
| 3650 | if (E->getQualifier()) { |
| 3651 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3652 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3653 | if (!Qualifier) |
| 3654 | return SemaRef.ExprError(); |
| 3655 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3656 | |
| 3657 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3658 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3659 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3660 | if (!ND) |
| 3661 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3663 | if (!getDerived().AlwaysRebuild() && |
| 3664 | Qualifier == E->getQualifier() && |
| 3665 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3666 | !E->hasExplicitTemplateArgumentList()) { |
| 3667 | |
| 3668 | // Mark it referenced in the new context regardless. |
| 3669 | // FIXME: this is a bit instantiation-specific. |
| 3670 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3671 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3673 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3674 | |
| 3675 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3676 | if (E->hasExplicitTemplateArgumentList()) { |
| 3677 | TemplateArgs = &TransArgs; |
| 3678 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3679 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3680 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3681 | TemplateArgumentLoc Loc; |
| 3682 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3683 | return SemaRef.ExprError(); |
| 3684 | TransArgs.addArgument(Loc); |
| 3685 | } |
| 3686 | } |
| 3687 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3688 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3689 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3692 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3693 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3694 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3695 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3696 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3698 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3700 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3701 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3703 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3704 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3706 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3707 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3708 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3710 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3712 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3714 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3716 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3717 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3718 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3719 | return SemaRef.Owned(E->Retain()); |
| 3720 | } |
| 3721 | |
| 3722 | template<typename Derived> |
| 3723 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3724 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3725 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3726 | if (SubExpr.isInvalid()) |
| 3727 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3728 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3729 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | return SemaRef.Owned(E->Retain()); |
| 3731 | |
| 3732 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3733 | E->getRParen()); |
| 3734 | } |
| 3735 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3736 | template<typename Derived> |
| 3737 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3738 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3739 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3740 | if (SubExpr.isInvalid()) |
| 3741 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3743 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3744 | return SemaRef.Owned(E->Retain()); |
| 3745 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3747 | E->getOpcode(), |
| 3748 | move(SubExpr)); |
| 3749 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3753 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3755 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3756 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3757 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3758 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3759 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3761 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3762 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3764 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3765 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3766 | E->getSourceRange()); |
| 3767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3769 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3770 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | // C++0x [expr.sizeof]p1: |
| 3772 | // The operand is either an expression, which is an unevaluated operand |
| 3773 | // [...] |
| 3774 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3775 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3777 | if (SubExpr.isInvalid()) |
| 3778 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3780 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3781 | return SemaRef.Owned(E->Retain()); |
| 3782 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3784 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3785 | E->isSizeOf(), |
| 3786 | E->getSourceRange()); |
| 3787 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3789 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3790 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3791 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3793 | if (LHS.isInvalid()) |
| 3794 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3796 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3797 | if (RHS.isInvalid()) |
| 3798 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
| 3800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3801 | if (!getDerived().AlwaysRebuild() && |
| 3802 | LHS.get() == E->getLHS() && |
| 3803 | RHS.get() == E->getRHS()) |
| 3804 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3806 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3807 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3808 | move(RHS), |
| 3809 | E->getRBracketLoc()); |
| 3810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | |
| 3812 | template<typename Derived> |
| 3813 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3814 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3815 | // Transform the callee. |
| 3816 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3817 | if (Callee.isInvalid()) |
| 3818 | return SemaRef.ExprError(); |
| 3819 | |
| 3820 | // Transform arguments. |
| 3821 | bool ArgChanged = false; |
| 3822 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3823 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3824 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3825 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3826 | if (Arg.isInvalid()) |
| 3827 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3828 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3829 | // FIXME: Wrong source location information for the ','. |
| 3830 | FakeCommaLocs.push_back( |
| 3831 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | |
| 3833 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | Args.push_back(Arg.takeAs<Expr>()); |
| 3835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | if (!getDerived().AlwaysRebuild() && |
| 3838 | Callee.get() == E->getCallee() && |
| 3839 | !ArgChanged) |
| 3840 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3843 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3844 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3845 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3846 | move_arg(Args), |
| 3847 | FakeCommaLocs.data(), |
| 3848 | E->getRParenLoc()); |
| 3849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3850 | |
| 3851 | template<typename Derived> |
| 3852 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3853 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3855 | if (Base.isInvalid()) |
| 3856 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3858 | NestedNameSpecifier *Qualifier = 0; |
| 3859 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3861 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3862 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3863 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3864 | return SemaRef.ExprError(); |
| 3865 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3867 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3868 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 3869 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3870 | if (!Member) |
| 3871 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3872 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3873 | if (!getDerived().AlwaysRebuild() && |
| 3874 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3875 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3876 | Member == E->getMemberDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3877 | !E->hasExplicitTemplateArgumentList()) { |
| 3878 | |
| 3879 | // Mark it referenced in the new context regardless. |
| 3880 | // FIXME: this is a bit instantiation-specific. |
| 3881 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3883 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3885 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3886 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3887 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3888 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3889 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3890 | TemplateArgumentLoc Loc; |
| 3891 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3892 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3893 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3894 | } |
| 3895 | } |
| 3896 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3897 | // FIXME: Bogus source location for the operator |
| 3898 | SourceLocation FakeOperatorLoc |
| 3899 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3900 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3901 | // FIXME: to do this check properly, we will need to preserve the |
| 3902 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3903 | // base (and therefore couldn't do the check) and a |
| 3904 | // nested-name-qualifier (and therefore could do the lookup). |
| 3905 | NamedDecl *FirstQualifierInScope = 0; |
| 3906 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3907 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3908 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3909 | Qualifier, |
| 3910 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3911 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3912 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3913 | (E->hasExplicitTemplateArgumentList() |
| 3914 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3915 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3918 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3919 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3920 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3922 | if (LHS.isInvalid()) |
| 3923 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3924 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3926 | if (RHS.isInvalid()) |
| 3927 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | if (!getDerived().AlwaysRebuild() && |
| 3930 | LHS.get() == E->getLHS() && |
| 3931 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3932 | return SemaRef.Owned(E->Retain()); |
| 3933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3935 | move(LHS), move(RHS)); |
| 3936 | } |
| 3937 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3939 | Sema::OwningExprResult |
| 3940 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3941 | CompoundAssignOperator *E) { |
| 3942 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3943 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3945 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3946 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3947 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3949 | if (Cond.isInvalid()) |
| 3950 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3951 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3953 | if (LHS.isInvalid()) |
| 3954 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3957 | if (RHS.isInvalid()) |
| 3958 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3959 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3960 | if (!getDerived().AlwaysRebuild() && |
| 3961 | Cond.get() == E->getCond() && |
| 3962 | LHS.get() == E->getLHS() && |
| 3963 | RHS.get() == E->getRHS()) |
| 3964 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
| 3966 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3967 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3969 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | move(RHS)); |
| 3971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
| 3973 | template<typename Derived> |
| 3974 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3975 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3976 | // Implicit casts are eliminated during transformation, since they |
| 3977 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3978 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3979 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3981 | template<typename Derived> |
| 3982 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3983 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3984 | TypeSourceInfo *OldT; |
| 3985 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3986 | { |
| 3987 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3990 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3992 | OldT = E->getTypeInfoAsWritten(); |
| 3993 | NewT = getDerived().TransformType(OldT); |
| 3994 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | return SemaRef.ExprError(); |
| 3996 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3998 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3999 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4000 | if (SubExpr.isInvalid()) |
| 4001 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4004 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4005 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4006 | return SemaRef.Owned(E->Retain()); |
| 4007 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4008 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4009 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4010 | E->getRParenLoc(), |
| 4011 | move(SubExpr)); |
| 4012 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4014 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4016 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4017 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4018 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4019 | if (!NewT) |
| 4020 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4021 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4022 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4023 | if (Init.isInvalid()) |
| 4024 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4025 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4026 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4027 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4029 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4030 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4031 | // Note: the expression type doesn't necessarily match the |
| 4032 | // type-as-written, but that's okay, because it should always be |
| 4033 | // derivable from the initializer. |
| 4034 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4035 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4036 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4037 | move(Init)); |
| 4038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4039 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4040 | template<typename Derived> |
| 4041 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4042 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4043 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4044 | if (Base.isInvalid()) |
| 4045 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4047 | if (!getDerived().AlwaysRebuild() && |
| 4048 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | return SemaRef.Owned(E->Retain()); |
| 4050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4052 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4053 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4054 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4055 | E->getAccessorLoc(), |
| 4056 | E->getAccessor()); |
| 4057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4059 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4060 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4061 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4062 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4065 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4066 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4067 | if (Init.isInvalid()) |
| 4068 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4070 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4071 | Inits.push_back(Init.takeAs<Expr>()); |
| 4072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4074 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | return SemaRef.Owned(E->Retain()); |
| 4076 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4078 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4079 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4081 | template<typename Derived> |
| 4082 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4083 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4086 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4087 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4088 | if (Init.isInvalid()) |
| 4089 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4091 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4092 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4093 | bool ExprChanged = false; |
| 4094 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4095 | DEnd = E->designators_end(); |
| 4096 | D != DEnd; ++D) { |
| 4097 | if (D->isFieldDesignator()) { |
| 4098 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4099 | D->getDotLoc(), |
| 4100 | D->getFieldLoc())); |
| 4101 | continue; |
| 4102 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4103 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | if (D->isArrayDesignator()) { |
| 4105 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4106 | if (Index.isInvalid()) |
| 4107 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4108 | |
| 4109 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4112 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4113 | ArrayExprs.push_back(Index.release()); |
| 4114 | continue; |
| 4115 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4117 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4118 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4119 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4120 | if (Start.isInvalid()) |
| 4121 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4122 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4123 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4124 | if (End.isInvalid()) |
| 4125 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | |
| 4127 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | End.get(), |
| 4129 | D->getLBracketLoc(), |
| 4130 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4133 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4134 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4135 | ArrayExprs.push_back(Start.release()); |
| 4136 | ArrayExprs.push_back(End.release()); |
| 4137 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4139 | if (!getDerived().AlwaysRebuild() && |
| 4140 | Init.get() == E->getInit() && |
| 4141 | !ExprChanged) |
| 4142 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4144 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4145 | E->getEqualOrColonLoc(), |
| 4146 | E->usesGNUSyntax(), move(Init)); |
| 4147 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4149 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4152 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4153 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4154 | |
| 4155 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4156 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4157 | QualType T = getDerived().TransformType(E->getType()); |
| 4158 | if (T.isNull()) |
| 4159 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4161 | if (!getDerived().AlwaysRebuild() && |
| 4162 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4163 | return SemaRef.Owned(E->Retain()); |
| 4164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4165 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4168 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4169 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4170 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | // FIXME: Do we want the type as written? |
| 4172 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4174 | { |
| 4175 | // FIXME: Source location isn't quite accurate. |
| 4176 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4177 | T = getDerived().TransformType(E->getType()); |
| 4178 | if (T.isNull()) |
| 4179 | return SemaRef.ExprError(); |
| 4180 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4183 | if (SubExpr.isInvalid()) |
| 4184 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4185 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4186 | if (!getDerived().AlwaysRebuild() && |
| 4187 | T == E->getType() && |
| 4188 | SubExpr.get() == E->getSubExpr()) |
| 4189 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4190 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4191 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4192 | T, E->getRParenLoc()); |
| 4193 | } |
| 4194 | |
| 4195 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4197 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | bool ArgumentChanged = false; |
| 4199 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4200 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4201 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4202 | if (Init.isInvalid()) |
| 4203 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4204 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4206 | Inits.push_back(Init.takeAs<Expr>()); |
| 4207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4209 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4210 | move_arg(Inits), |
| 4211 | E->getRParenLoc()); |
| 4212 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | /// \brief Transform an address-of-label expression. |
| 4215 | /// |
| 4216 | /// By default, the transformation of an address-of-label expression always |
| 4217 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4218 | /// the corresponding label statement by semantic analysis. |
| 4219 | template<typename Derived> |
| 4220 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4221 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4223 | E->getLabel()); |
| 4224 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | |
| 4226 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4227 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4228 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4230 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4231 | if (SubStmt.isInvalid()) |
| 4232 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4234 | if (!getDerived().AlwaysRebuild() && |
| 4235 | SubStmt.get() == E->getSubStmt()) |
| 4236 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4237 | |
| 4238 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | move(SubStmt), |
| 4240 | E->getRParenLoc()); |
| 4241 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4243 | template<typename Derived> |
| 4244 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4245 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | QualType T1, T2; |
| 4247 | { |
| 4248 | // FIXME: Source location isn't quite accurate. |
| 4249 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4251 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4252 | if (T1.isNull()) |
| 4253 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4256 | if (T2.isNull()) |
| 4257 | return SemaRef.ExprError(); |
| 4258 | } |
| 4259 | |
| 4260 | if (!getDerived().AlwaysRebuild() && |
| 4261 | T1 == E->getArgType1() && |
| 4262 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | return SemaRef.Owned(E->Retain()); |
| 4264 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4265 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4266 | T1, T2, E->getRParenLoc()); |
| 4267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4268 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4269 | template<typename Derived> |
| 4270 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4271 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4272 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4273 | if (Cond.isInvalid()) |
| 4274 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4276 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4277 | if (LHS.isInvalid()) |
| 4278 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4280 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4281 | if (RHS.isInvalid()) |
| 4282 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4284 | if (!getDerived().AlwaysRebuild() && |
| 4285 | Cond.get() == E->getCond() && |
| 4286 | LHS.get() == E->getLHS() && |
| 4287 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | return SemaRef.Owned(E->Retain()); |
| 4289 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4290 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4291 | move(Cond), move(LHS), move(RHS), |
| 4292 | E->getRParenLoc()); |
| 4293 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4294 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4295 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4297 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4298 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | template<typename Derived> |
| 4302 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4303 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4304 | switch (E->getOperator()) { |
| 4305 | case OO_New: |
| 4306 | case OO_Delete: |
| 4307 | case OO_Array_New: |
| 4308 | case OO_Array_Delete: |
| 4309 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4310 | return SemaRef.ExprError(); |
| 4311 | |
| 4312 | case OO_Call: { |
| 4313 | // This is a call to an object's operator(). |
| 4314 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4315 | |
| 4316 | // Transform the object itself. |
| 4317 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4318 | if (Object.isInvalid()) |
| 4319 | return SemaRef.ExprError(); |
| 4320 | |
| 4321 | // FIXME: Poor location information |
| 4322 | SourceLocation FakeLParenLoc |
| 4323 | = SemaRef.PP.getLocForEndOfToken( |
| 4324 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4325 | |
| 4326 | // Transform the call arguments. |
| 4327 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4328 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4329 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4330 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4331 | break; |
| 4332 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4333 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4334 | if (Arg.isInvalid()) |
| 4335 | return SemaRef.ExprError(); |
| 4336 | |
| 4337 | // FIXME: Poor source location information. |
| 4338 | SourceLocation FakeCommaLoc |
| 4339 | = SemaRef.PP.getLocForEndOfToken( |
| 4340 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4341 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4342 | Args.push_back(Arg.release()); |
| 4343 | } |
| 4344 | |
| 4345 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4346 | move_arg(Args), |
| 4347 | FakeCommaLocs.data(), |
| 4348 | E->getLocEnd()); |
| 4349 | } |
| 4350 | |
| 4351 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4352 | case OO_##Name: |
| 4353 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4354 | #include "clang/Basic/OperatorKinds.def" |
| 4355 | case OO_Subscript: |
| 4356 | // Handled below. |
| 4357 | break; |
| 4358 | |
| 4359 | case OO_Conditional: |
| 4360 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4361 | return SemaRef.ExprError(); |
| 4362 | |
| 4363 | case OO_None: |
| 4364 | case NUM_OVERLOADED_OPERATORS: |
| 4365 | llvm_unreachable("not an overloaded operator?"); |
| 4366 | return SemaRef.ExprError(); |
| 4367 | } |
| 4368 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4369 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4370 | if (Callee.isInvalid()) |
| 4371 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4373 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | if (First.isInvalid()) |
| 4375 | return SemaRef.ExprError(); |
| 4376 | |
| 4377 | OwningExprResult Second(SemaRef); |
| 4378 | if (E->getNumArgs() == 2) { |
| 4379 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4380 | if (Second.isInvalid()) |
| 4381 | return SemaRef.ExprError(); |
| 4382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | if (!getDerived().AlwaysRebuild() && |
| 4385 | Callee.get() == E->getCallee() && |
| 4386 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4388 | return SemaRef.Owned(E->Retain()); |
| 4389 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4391 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4393 | move(First), |
| 4394 | move(Second)); |
| 4395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4397 | template<typename Derived> |
| 4398 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4399 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4400 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4403 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4405 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4406 | TypeSourceInfo *OldT; |
| 4407 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | { |
| 4409 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4410 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4411 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4412 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4414 | OldT = E->getTypeInfoAsWritten(); |
| 4415 | NewT = getDerived().TransformType(OldT); |
| 4416 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | return SemaRef.ExprError(); |
| 4418 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4419 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4420 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4421 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4422 | if (SubExpr.isInvalid()) |
| 4423 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4426 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4428 | return SemaRef.Owned(E->Retain()); |
| 4429 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4430 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4431 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4433 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4434 | SourceLocation FakeRParenLoc |
| 4435 | = SemaRef.PP.getLocForEndOfToken( |
| 4436 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4437 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4439 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4440 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4441 | FakeRAngleLoc, |
| 4442 | FakeRAngleLoc, |
| 4443 | move(SubExpr), |
| 4444 | FakeRParenLoc); |
| 4445 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4446 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | template<typename Derived> |
| 4448 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4449 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4450 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4451 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4452 | |
| 4453 | template<typename Derived> |
| 4454 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4455 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4456 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | template<typename Derived> |
| 4460 | Sema::OwningExprResult |
| 4461 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4462 | CXXReinterpretCastExpr *E) { |
| 4463 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | template<typename Derived> |
| 4467 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4468 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4469 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | template<typename Derived> |
| 4473 | Sema::OwningExprResult |
| 4474 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4475 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4476 | TypeSourceInfo *OldT; |
| 4477 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4478 | { |
| 4479 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4480 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4481 | OldT = E->getTypeInfoAsWritten(); |
| 4482 | NewT = getDerived().TransformType(OldT); |
| 4483 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4484 | return SemaRef.ExprError(); |
| 4485 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4487 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4488 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4489 | if (SubExpr.isInvalid()) |
| 4490 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4491 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4493 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4494 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4495 | return SemaRef.Owned(E->Retain()); |
| 4496 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | // FIXME: The end of the type's source range is wrong |
| 4498 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4499 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4500 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4502 | move(SubExpr), |
| 4503 | E->getRParenLoc()); |
| 4504 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | template<typename Derived> |
| 4507 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4508 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | if (E->isTypeOperand()) { |
| 4510 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4513 | if (T.isNull()) |
| 4514 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4516 | if (!getDerived().AlwaysRebuild() && |
| 4517 | T == E->getTypeOperand()) |
| 4518 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4521 | /*FIXME:*/E->getLocStart(), |
| 4522 | T, |
| 4523 | E->getLocEnd()); |
| 4524 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | // We don't know whether the expression is potentially evaluated until |
| 4527 | // after we perform semantic analysis, so the expression is potentially |
| 4528 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4530 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4531 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4533 | if (SubExpr.isInvalid()) |
| 4534 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4536 | if (!getDerived().AlwaysRebuild() && |
| 4537 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | return SemaRef.Owned(E->Retain()); |
| 4539 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4541 | /*FIXME:*/E->getLocStart(), |
| 4542 | move(SubExpr), |
| 4543 | E->getLocEnd()); |
| 4544 | } |
| 4545 | |
| 4546 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4548 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4550 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4551 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4552 | template<typename Derived> |
| 4553 | Sema::OwningExprResult |
| 4554 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4555 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | template<typename Derived> |
| 4560 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4561 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4562 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4563 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4564 | QualType T = getDerived().TransformType(E->getType()); |
| 4565 | if (T.isNull()) |
| 4566 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4567 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4568 | if (!getDerived().AlwaysRebuild() && |
| 4569 | T == E->getType()) |
| 4570 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4572 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | template<typename Derived> |
| 4576 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4577 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4578 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4579 | if (SubExpr.isInvalid()) |
| 4580 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | if (!getDerived().AlwaysRebuild() && |
| 4583 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4585 | |
| 4586 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4587 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4589 | template<typename Derived> |
| 4590 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4591 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4592 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4593 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4594 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4595 | if (!Param) |
| 4596 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4597 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4598 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4599 | Param == E->getParam()) |
| 4600 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4602 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4603 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4605 | template<typename Derived> |
| 4606 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4607 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4608 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4609 | |
| 4610 | QualType T = getDerived().TransformType(E->getType()); |
| 4611 | if (T.isNull()) |
| 4612 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4613 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4614 | if (!getDerived().AlwaysRebuild() && |
| 4615 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | return SemaRef.Owned(E->Retain()); |
| 4617 | |
| 4618 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4620 | T, |
| 4621 | E->getRParenLoc()); |
| 4622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4623 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4624 | template<typename Derived> |
| 4625 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4626 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4627 | // Transform the type that we're allocating |
| 4628 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4629 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4630 | if (AllocType.isNull()) |
| 4631 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | // Transform the size of the array we're allocating (if any). |
| 4634 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4635 | if (ArraySize.isInvalid()) |
| 4636 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | // Transform the placement arguments (if any). |
| 4639 | bool ArgumentChanged = false; |
| 4640 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4641 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4642 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4643 | if (Arg.isInvalid()) |
| 4644 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4647 | PlacementArgs.push_back(Arg.take()); |
| 4648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4650 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4652 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4653 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4654 | if (Arg.isInvalid()) |
| 4655 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4657 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4658 | ConstructorArgs.push_back(Arg.take()); |
| 4659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4660 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4661 | // Transform constructor, new operator, and delete operator. |
| 4662 | CXXConstructorDecl *Constructor = 0; |
| 4663 | if (E->getConstructor()) { |
| 4664 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4665 | getDerived().TransformDecl(E->getLocStart(), |
| 4666 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4667 | if (!Constructor) |
| 4668 | return SemaRef.ExprError(); |
| 4669 | } |
| 4670 | |
| 4671 | FunctionDecl *OperatorNew = 0; |
| 4672 | if (E->getOperatorNew()) { |
| 4673 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4674 | getDerived().TransformDecl(E->getLocStart(), |
| 4675 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4676 | if (!OperatorNew) |
| 4677 | return SemaRef.ExprError(); |
| 4678 | } |
| 4679 | |
| 4680 | FunctionDecl *OperatorDelete = 0; |
| 4681 | if (E->getOperatorDelete()) { |
| 4682 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4683 | getDerived().TransformDecl(E->getLocStart(), |
| 4684 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4685 | if (!OperatorDelete) |
| 4686 | return SemaRef.ExprError(); |
| 4687 | } |
| 4688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | if (!getDerived().AlwaysRebuild() && |
| 4690 | AllocType == E->getAllocatedType() && |
| 4691 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4692 | Constructor == E->getConstructor() && |
| 4693 | OperatorNew == E->getOperatorNew() && |
| 4694 | OperatorDelete == E->getOperatorDelete() && |
| 4695 | !ArgumentChanged) { |
| 4696 | // Mark any declarations we need as referenced. |
| 4697 | // FIXME: instantiation-specific. |
| 4698 | if (Constructor) |
| 4699 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4700 | if (OperatorNew) |
| 4701 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4702 | if (OperatorDelete) |
| 4703 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4707 | if (!ArraySize.get()) { |
| 4708 | // If no array size was specified, but the new expression was |
| 4709 | // instantiated with an array type (e.g., "new T" where T is |
| 4710 | // instantiated with "int[4]"), extract the outer bound from the |
| 4711 | // array type as our array size. We do this with constant and |
| 4712 | // dependently-sized array types. |
| 4713 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4714 | if (!ArrayT) { |
| 4715 | // Do nothing |
| 4716 | } else if (const ConstantArrayType *ConsArrayT |
| 4717 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4718 | ArraySize |
| 4719 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4720 | ConsArrayT->getSize(), |
| 4721 | SemaRef.Context.getSizeType(), |
| 4722 | /*FIXME:*/E->getLocStart())); |
| 4723 | AllocType = ConsArrayT->getElementType(); |
| 4724 | } else if (const DependentSizedArrayType *DepArrayT |
| 4725 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4726 | if (DepArrayT->getSizeExpr()) { |
| 4727 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4728 | AllocType = DepArrayT->getElementType(); |
| 4729 | } |
| 4730 | } |
| 4731 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4732 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4733 | E->isGlobalNew(), |
| 4734 | /*FIXME:*/E->getLocStart(), |
| 4735 | move_arg(PlacementArgs), |
| 4736 | /*FIXME:*/E->getLocStart(), |
| 4737 | E->isParenTypeId(), |
| 4738 | AllocType, |
| 4739 | /*FIXME:*/E->getLocStart(), |
| 4740 | /*FIXME:*/SourceRange(), |
| 4741 | move(ArraySize), |
| 4742 | /*FIXME:*/E->getLocStart(), |
| 4743 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | template<typename Derived> |
| 4748 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4749 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4751 | if (Operand.isInvalid()) |
| 4752 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4754 | // Transform the delete operator, if known. |
| 4755 | FunctionDecl *OperatorDelete = 0; |
| 4756 | if (E->getOperatorDelete()) { |
| 4757 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4758 | getDerived().TransformDecl(E->getLocStart(), |
| 4759 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4760 | if (!OperatorDelete) |
| 4761 | return SemaRef.ExprError(); |
| 4762 | } |
| 4763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4765 | Operand.get() == E->getArgument() && |
| 4766 | OperatorDelete == E->getOperatorDelete()) { |
| 4767 | // Mark any declarations we need as referenced. |
| 4768 | // FIXME: instantiation-specific. |
| 4769 | if (OperatorDelete) |
| 4770 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4771 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4772 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4774 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4775 | E->isGlobalDelete(), |
| 4776 | E->isArrayForm(), |
| 4777 | move(Operand)); |
| 4778 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | template<typename Derived> |
| 4781 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4782 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4783 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4784 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4785 | if (Base.isInvalid()) |
| 4786 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4788 | Sema::TypeTy *ObjectTypePtr = 0; |
| 4789 | bool MayBePseudoDestructor = false; |
| 4790 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4791 | E->getOperatorLoc(), |
| 4792 | E->isArrow()? tok::arrow : tok::period, |
| 4793 | ObjectTypePtr, |
| 4794 | MayBePseudoDestructor); |
| 4795 | if (Base.isInvalid()) |
| 4796 | return SemaRef.ExprError(); |
| 4797 | |
| 4798 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4799 | NestedNameSpecifier *Qualifier |
| 4800 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4801 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4802 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4803 | if (E->getQualifier() && !Qualifier) |
| 4804 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4805 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4806 | PseudoDestructorTypeStorage Destroyed; |
| 4807 | if (E->getDestroyedTypeInfo()) { |
| 4808 | TypeSourceInfo *DestroyedTypeInfo |
| 4809 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 4810 | if (!DestroyedTypeInfo) |
| 4811 | return SemaRef.ExprError(); |
| 4812 | Destroyed = DestroyedTypeInfo; |
| 4813 | } else if (ObjectType->isDependentType()) { |
| 4814 | // We aren't likely to be able to resolve the identifier down to a type |
| 4815 | // now anyway, so just retain the identifier. |
| 4816 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 4817 | E->getDestroyedTypeLoc()); |
| 4818 | } else { |
| 4819 | // Look for a destructor known with the given name. |
| 4820 | CXXScopeSpec SS; |
| 4821 | if (Qualifier) { |
| 4822 | SS.setScopeRep(Qualifier); |
| 4823 | SS.setRange(E->getQualifierRange()); |
| 4824 | } |
| 4825 | |
| 4826 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 4827 | *E->getDestroyedTypeIdentifier(), |
| 4828 | E->getDestroyedTypeLoc(), |
| 4829 | /*Scope=*/0, |
| 4830 | SS, ObjectTypePtr, |
| 4831 | false); |
| 4832 | if (!T) |
| 4833 | return SemaRef.ExprError(); |
| 4834 | |
| 4835 | Destroyed |
| 4836 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 4837 | E->getDestroyedTypeLoc()); |
| 4838 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4840 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4841 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4842 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 4843 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4844 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4845 | return SemaRef.ExprError(); |
| 4846 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4848 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4849 | E->getOperatorLoc(), |
| 4850 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4851 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4852 | E->getQualifierRange(), |
| 4853 | ScopeTypeInfo, |
| 4854 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 4855 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4856 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4857 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4859 | template<typename Derived> |
| 4860 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4861 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4862 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4863 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4864 | |
| 4865 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4866 | Sema::LookupOrdinaryName); |
| 4867 | |
| 4868 | // Transform all the decls. |
| 4869 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4870 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4871 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 4872 | getDerived().TransformDecl(Old->getNameLoc(), |
| 4873 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4874 | if (!InstD) { |
| 4875 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4876 | // This can happen because of dependent hiding. |
| 4877 | if (isa<UsingShadowDecl>(*I)) |
| 4878 | continue; |
| 4879 | else |
| 4880 | return SemaRef.ExprError(); |
| 4881 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4882 | |
| 4883 | // Expand using declarations. |
| 4884 | if (isa<UsingDecl>(InstD)) { |
| 4885 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4886 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4887 | E = UD->shadow_end(); I != E; ++I) |
| 4888 | R.addDecl(*I); |
| 4889 | continue; |
| 4890 | } |
| 4891 | |
| 4892 | R.addDecl(InstD); |
| 4893 | } |
| 4894 | |
| 4895 | // Resolve a kind, but don't do any further analysis. If it's |
| 4896 | // ambiguous, the callee needs to deal with it. |
| 4897 | R.resolveKind(); |
| 4898 | |
| 4899 | // Rebuild the nested-name qualifier, if present. |
| 4900 | CXXScopeSpec SS; |
| 4901 | NestedNameSpecifier *Qualifier = 0; |
| 4902 | if (Old->getQualifier()) { |
| 4903 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4904 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4905 | if (!Qualifier) |
| 4906 | return SemaRef.ExprError(); |
| 4907 | |
| 4908 | SS.setScopeRep(Qualifier); |
| 4909 | SS.setRange(Old->getQualifierRange()); |
| 4910 | } |
| 4911 | |
| 4912 | // If we have no template arguments, it's a normal declaration name. |
| 4913 | if (!Old->hasExplicitTemplateArgs()) |
| 4914 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4915 | |
| 4916 | // If we have template arguments, rebuild them, then rebuild the |
| 4917 | // templateid expression. |
| 4918 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4919 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4920 | TemplateArgumentLoc Loc; |
| 4921 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4922 | return SemaRef.ExprError(); |
| 4923 | TransArgs.addArgument(Loc); |
| 4924 | } |
| 4925 | |
| 4926 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4927 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4928 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4930 | template<typename Derived> |
| 4931 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4932 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4933 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4934 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4935 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4936 | if (T.isNull()) |
| 4937 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4939 | if (!getDerived().AlwaysRebuild() && |
| 4940 | T == E->getQueriedType()) |
| 4941 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4942 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4943 | // FIXME: Bad location information |
| 4944 | SourceLocation FakeLParenLoc |
| 4945 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4946 | |
| 4947 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | E->getLocStart(), |
| 4949 | /*FIXME:*/FakeLParenLoc, |
| 4950 | T, |
| 4951 | E->getLocEnd()); |
| 4952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4953 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4954 | template<typename Derived> |
| 4955 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4956 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4957 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4958 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4959 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4960 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | if (!NNS) |
| 4962 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4963 | |
| 4964 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4965 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4966 | if (!Name) |
| 4967 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4969 | if (!E->hasExplicitTemplateArgs()) { |
| 4970 | if (!getDerived().AlwaysRebuild() && |
| 4971 | NNS == E->getQualifier() && |
| 4972 | Name == E->getDeclName()) |
| 4973 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4974 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4975 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4976 | E->getQualifierRange(), |
| 4977 | Name, E->getLocation(), |
| 4978 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4979 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4980 | |
| 4981 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4982 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4983 | TemplateArgumentLoc Loc; |
| 4984 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4985 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4986 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4987 | } |
| 4988 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4989 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4990 | E->getQualifierRange(), |
| 4991 | Name, E->getLocation(), |
| 4992 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | template<typename Derived> |
| 4996 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4997 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4998 | // CXXConstructExprs are always implicit, so when we have a |
| 4999 | // 1-argument construction we just transform that argument. |
| 5000 | if (E->getNumArgs() == 1 || |
| 5001 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5002 | return getDerived().TransformExpr(E->getArg(0)); |
| 5003 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5004 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5005 | |
| 5006 | QualType T = getDerived().TransformType(E->getType()); |
| 5007 | if (T.isNull()) |
| 5008 | return SemaRef.ExprError(); |
| 5009 | |
| 5010 | CXXConstructorDecl *Constructor |
| 5011 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5012 | getDerived().TransformDecl(E->getLocStart(), |
| 5013 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5014 | if (!Constructor) |
| 5015 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5017 | bool ArgumentChanged = false; |
| 5018 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5020 | ArgEnd = E->arg_end(); |
| 5021 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5022 | if (getDerived().DropCallArgument(*Arg)) { |
| 5023 | ArgumentChanged = true; |
| 5024 | break; |
| 5025 | } |
| 5026 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5027 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5028 | if (TransArg.isInvalid()) |
| 5029 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5030 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5031 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5032 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5033 | } |
| 5034 | |
| 5035 | if (!getDerived().AlwaysRebuild() && |
| 5036 | T == E->getType() && |
| 5037 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5038 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5039 | // Mark the constructor as referenced. |
| 5040 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5041 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5042 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5044 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5045 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5046 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5047 | move_arg(Args)); |
| 5048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5050 | /// \brief Transform a C++ temporary-binding expression. |
| 5051 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5052 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5053 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5054 | template<typename Derived> |
| 5055 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5056 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5057 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5060 | /// \brief Transform a C++ reference-binding expression. |
| 5061 | /// |
| 5062 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5063 | /// transform the subexpression and return that. |
| 5064 | template<typename Derived> |
| 5065 | Sema::OwningExprResult |
| 5066 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5067 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5068 | } |
| 5069 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5070 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5071 | /// be destroyed after the expression is evaluated. |
| 5072 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5073 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5074 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | template<typename Derived> |
| 5076 | Sema::OwningExprResult |
| 5077 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5078 | CXXExprWithTemporaries *E) { |
| 5079 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5082 | template<typename Derived> |
| 5083 | Sema::OwningExprResult |
| 5084 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5085 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5087 | QualType T = getDerived().TransformType(E->getType()); |
| 5088 | if (T.isNull()) |
| 5089 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5091 | CXXConstructorDecl *Constructor |
| 5092 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5093 | getDerived().TransformDecl(E->getLocStart(), |
| 5094 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | if (!Constructor) |
| 5096 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5098 | bool ArgumentChanged = false; |
| 5099 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5100 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5102 | ArgEnd = E->arg_end(); |
| 5103 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5104 | if (getDerived().DropCallArgument(*Arg)) { |
| 5105 | ArgumentChanged = true; |
| 5106 | break; |
| 5107 | } |
| 5108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5109 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5110 | if (TransArg.isInvalid()) |
| 5111 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5112 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5113 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5114 | Args.push_back((Expr *)TransArg.release()); |
| 5115 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5117 | if (!getDerived().AlwaysRebuild() && |
| 5118 | T == E->getType() && |
| 5119 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5120 | !ArgumentChanged) { |
| 5121 | // FIXME: Instantiation-specific |
| 5122 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5123 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5125 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5126 | // FIXME: Bogus location information |
| 5127 | SourceLocation CommaLoc; |
| 5128 | if (Args.size() > 1) { |
| 5129 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5130 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5131 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5132 | } |
| 5133 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5134 | T, |
| 5135 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5136 | move_arg(Args), |
| 5137 | &CommaLoc, |
| 5138 | E->getLocEnd()); |
| 5139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5141 | template<typename Derived> |
| 5142 | Sema::OwningExprResult |
| 5143 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5144 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5146 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5147 | if (T.isNull()) |
| 5148 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5150 | bool ArgumentChanged = false; |
| 5151 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5152 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5153 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5154 | ArgEnd = E->arg_end(); |
| 5155 | Arg != ArgEnd; ++Arg) { |
| 5156 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5157 | if (TransArg.isInvalid()) |
| 5158 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5159 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5160 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5161 | FakeCommaLocs.push_back( |
| 5162 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5163 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5164 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5165 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5166 | if (!getDerived().AlwaysRebuild() && |
| 5167 | T == E->getTypeAsWritten() && |
| 5168 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | return SemaRef.Owned(E->Retain()); |
| 5170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5171 | // FIXME: we're faking the locations of the commas |
| 5172 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5173 | T, |
| 5174 | E->getLParenLoc(), |
| 5175 | move_arg(Args), |
| 5176 | FakeCommaLocs.data(), |
| 5177 | E->getRParenLoc()); |
| 5178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | template<typename Derived> |
| 5181 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5182 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5183 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5185 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5186 | Expr *OldBase; |
| 5187 | QualType BaseType; |
| 5188 | QualType ObjectType; |
| 5189 | if (!E->isImplicitAccess()) { |
| 5190 | OldBase = E->getBase(); |
| 5191 | Base = getDerived().TransformExpr(OldBase); |
| 5192 | if (Base.isInvalid()) |
| 5193 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5195 | // Start the member reference and compute the object's type. |
| 5196 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5197 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5198 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5199 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5200 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5201 | ObjectTy, |
| 5202 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5203 | if (Base.isInvalid()) |
| 5204 | return SemaRef.ExprError(); |
| 5205 | |
| 5206 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5207 | BaseType = ((Expr*) Base.get())->getType(); |
| 5208 | } else { |
| 5209 | OldBase = 0; |
| 5210 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5211 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5212 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5214 | // Transform the first part of the nested-name-specifier that qualifies |
| 5215 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5216 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5217 | = getDerived().TransformFirstQualifierInScope( |
| 5218 | E->getFirstQualifierFoundInScope(), |
| 5219 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5220 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5221 | NestedNameSpecifier *Qualifier = 0; |
| 5222 | if (E->getQualifier()) { |
| 5223 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5224 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5225 | ObjectType, |
| 5226 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5227 | if (!Qualifier) |
| 5228 | return SemaRef.ExprError(); |
| 5229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
| 5231 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5232 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5233 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5234 | if (!Name) |
| 5235 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5237 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5238 | // This is a reference to a member without an explicitly-specified |
| 5239 | // template argument list. Optimize for this common case. |
| 5240 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5241 | Base.get() == OldBase && |
| 5242 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5243 | Qualifier == E->getQualifier() && |
| 5244 | Name == E->getMember() && |
| 5245 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | return SemaRef.Owned(E->Retain()); |
| 5247 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5248 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5249 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5250 | E->isArrow(), |
| 5251 | E->getOperatorLoc(), |
| 5252 | Qualifier, |
| 5253 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5254 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5255 | Name, |
| 5256 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5257 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5260 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5261 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5262 | TemplateArgumentLoc Loc; |
| 5263 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5264 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5265 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5267 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5268 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5269 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5270 | E->isArrow(), |
| 5271 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5272 | Qualifier, |
| 5273 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5274 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5275 | Name, |
| 5276 | E->getMemberLoc(), |
| 5277 | &TransArgs); |
| 5278 | } |
| 5279 | |
| 5280 | template<typename Derived> |
| 5281 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5282 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5283 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5284 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5285 | QualType BaseType; |
| 5286 | if (!Old->isImplicitAccess()) { |
| 5287 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5288 | if (Base.isInvalid()) |
| 5289 | return SemaRef.ExprError(); |
| 5290 | BaseType = ((Expr*) Base.get())->getType(); |
| 5291 | } else { |
| 5292 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5293 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5294 | |
| 5295 | NestedNameSpecifier *Qualifier = 0; |
| 5296 | if (Old->getQualifier()) { |
| 5297 | Qualifier |
| 5298 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5299 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5300 | if (Qualifier == 0) |
| 5301 | return SemaRef.ExprError(); |
| 5302 | } |
| 5303 | |
| 5304 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5305 | Sema::LookupOrdinaryName); |
| 5306 | |
| 5307 | // Transform all the decls. |
| 5308 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5309 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5310 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5311 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5312 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5313 | if (!InstD) { |
| 5314 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5315 | // This can happen because of dependent hiding. |
| 5316 | if (isa<UsingShadowDecl>(*I)) |
| 5317 | continue; |
| 5318 | else |
| 5319 | return SemaRef.ExprError(); |
| 5320 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5321 | |
| 5322 | // Expand using declarations. |
| 5323 | if (isa<UsingDecl>(InstD)) { |
| 5324 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5325 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5326 | E = UD->shadow_end(); I != E; ++I) |
| 5327 | R.addDecl(*I); |
| 5328 | continue; |
| 5329 | } |
| 5330 | |
| 5331 | R.addDecl(InstD); |
| 5332 | } |
| 5333 | |
| 5334 | R.resolveKind(); |
| 5335 | |
| 5336 | TemplateArgumentListInfo TransArgs; |
| 5337 | if (Old->hasExplicitTemplateArgs()) { |
| 5338 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5339 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5340 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5341 | TemplateArgumentLoc Loc; |
| 5342 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5343 | Loc)) |
| 5344 | return SemaRef.ExprError(); |
| 5345 | TransArgs.addArgument(Loc); |
| 5346 | } |
| 5347 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5348 | |
| 5349 | // FIXME: to do this check properly, we will need to preserve the |
| 5350 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5351 | // base (and therefore couldn't do the check) and a |
| 5352 | // nested-name-qualifier (and therefore could do the lookup). |
| 5353 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5354 | |
| 5355 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5356 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5357 | Old->getOperatorLoc(), |
| 5358 | Old->isArrow(), |
| 5359 | Qualifier, |
| 5360 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5361 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5362 | R, |
| 5363 | (Old->hasExplicitTemplateArgs() |
| 5364 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | template<typename Derived> |
| 5368 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5369 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5370 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5371 | } |
| 5372 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5373 | template<typename Derived> |
| 5374 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5375 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5376 | // FIXME: poor source location |
| 5377 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5378 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5379 | if (EncodedType.isNull()) |
| 5380 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5382 | if (!getDerived().AlwaysRebuild() && |
| 5383 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5385 | |
| 5386 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5387 | EncodedType, |
| 5388 | E->getRParenLoc()); |
| 5389 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5391 | template<typename Derived> |
| 5392 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5393 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5394 | // FIXME: Implement this! |
| 5395 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5396 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5397 | } |
| 5398 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5399 | template<typename Derived> |
| 5400 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5401 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5403 | } |
| 5404 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | template<typename Derived> |
| 5406 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5407 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5408 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5409 | = cast_or_null<ObjCProtocolDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5410 | getDerived().TransformDecl(E->getLocStart(), |
| 5411 | E->getProtocol())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5412 | if (!Protocol) |
| 5413 | return SemaRef.ExprError(); |
| 5414 | |
| 5415 | if (!getDerived().AlwaysRebuild() && |
| 5416 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | return SemaRef.Owned(E->Retain()); |
| 5418 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5419 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5420 | E->getAtLoc(), |
| 5421 | /*FIXME:*/E->getAtLoc(), |
| 5422 | /*FIXME:*/E->getAtLoc(), |
| 5423 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5427 | template<typename Derived> |
| 5428 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5429 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5430 | // FIXME: Implement this! |
| 5431 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5432 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5433 | } |
| 5434 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5435 | template<typename Derived> |
| 5436 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5437 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5438 | // FIXME: Implement this! |
| 5439 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5440 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5441 | } |
| 5442 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5443 | template<typename Derived> |
| 5444 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5445 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5446 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5447 | // FIXME: Implement this! |
| 5448 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5449 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5450 | } |
| 5451 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | template<typename Derived> |
| 5453 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5454 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5455 | // FIXME: Implement this! |
| 5456 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5457 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5458 | } |
| 5459 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | template<typename Derived> |
| 5461 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5462 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5463 | // FIXME: Implement this! |
| 5464 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5466 | } |
| 5467 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5468 | template<typename Derived> |
| 5469 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5470 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5471 | bool ArgumentChanged = false; |
| 5472 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5473 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5474 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5475 | if (SubExpr.isInvalid()) |
| 5476 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5477 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5478 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5479 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5480 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5481 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5482 | if (!getDerived().AlwaysRebuild() && |
| 5483 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5484 | return SemaRef.Owned(E->Retain()); |
| 5485 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5486 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5487 | move_arg(SubExprs), |
| 5488 | E->getRParenLoc()); |
| 5489 | } |
| 5490 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5491 | template<typename Derived> |
| 5492 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5493 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5494 | // FIXME: Implement this! |
| 5495 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5496 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5497 | } |
| 5498 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5499 | template<typename Derived> |
| 5500 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5501 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | // FIXME: Implement this! |
| 5503 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5507 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5508 | // Type reconstruction |
| 5509 | //===----------------------------------------------------------------------===// |
| 5510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5512 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5513 | SourceLocation Star) { |
| 5514 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5515 | getDerived().getBaseEntity()); |
| 5516 | } |
| 5517 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5519 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5520 | SourceLocation Star) { |
| 5521 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5522 | getDerived().getBaseEntity()); |
| 5523 | } |
| 5524 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5525 | template<typename Derived> |
| 5526 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5527 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5528 | bool WrittenAsLValue, |
| 5529 | SourceLocation Sigil) { |
| 5530 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5531 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5535 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5536 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5537 | QualType ClassType, |
| 5538 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5539 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5540 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5544 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5545 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5546 | SourceLocation Sigil) { |
| 5547 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5548 | getDerived().getBaseEntity()); |
| 5549 | } |
| 5550 | |
| 5551 | template<typename Derived> |
| 5552 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5553 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5554 | ArrayType::ArraySizeModifier SizeMod, |
| 5555 | const llvm::APInt *Size, |
| 5556 | Expr *SizeExpr, |
| 5557 | unsigned IndexTypeQuals, |
| 5558 | SourceRange BracketsRange) { |
| 5559 | if (SizeExpr || !Size) |
| 5560 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5561 | IndexTypeQuals, BracketsRange, |
| 5562 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5563 | |
| 5564 | QualType Types[] = { |
| 5565 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5566 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5567 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5568 | }; |
| 5569 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5570 | QualType SizeType; |
| 5571 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5572 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5573 | SizeType = Types[I]; |
| 5574 | break; |
| 5575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5576 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5577 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5578 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5579 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5580 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5581 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5583 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5584 | QualType |
| 5585 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5586 | ArrayType::ArraySizeModifier SizeMod, |
| 5587 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5588 | unsigned IndexTypeQuals, |
| 5589 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5590 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5591 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5597 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5598 | unsigned IndexTypeQuals, |
| 5599 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5600 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5601 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5602 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5604 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5605 | QualType |
| 5606 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5607 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5608 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5609 | unsigned IndexTypeQuals, |
| 5610 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5612 | SizeExpr.takeAs<Expr>(), |
| 5613 | IndexTypeQuals, BracketsRange); |
| 5614 | } |
| 5615 | |
| 5616 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5617 | QualType |
| 5618 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5619 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5620 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5621 | unsigned IndexTypeQuals, |
| 5622 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5623 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5624 | SizeExpr.takeAs<Expr>(), |
| 5625 | IndexTypeQuals, BracketsRange); |
| 5626 | } |
| 5627 | |
| 5628 | template<typename Derived> |
| 5629 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5630 | unsigned NumElements, |
| 5631 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5632 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5633 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5634 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5636 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5637 | template<typename Derived> |
| 5638 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5639 | unsigned NumElements, |
| 5640 | SourceLocation AttributeLoc) { |
| 5641 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5642 | NumElements, true); |
| 5643 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5644 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5645 | AttributeLoc); |
| 5646 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5647 | AttributeLoc); |
| 5648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5649 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5650 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5651 | QualType |
| 5652 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5653 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5654 | SourceLocation AttributeLoc) { |
| 5655 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5657 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5658 | template<typename Derived> |
| 5659 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5660 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5661 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5663 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5665 | Quals, |
| 5666 | getDerived().getBaseLocation(), |
| 5667 | getDerived().getBaseEntity()); |
| 5668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5669 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5670 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5671 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5672 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5673 | } |
| 5674 | |
| 5675 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5676 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5677 | assert(D && "no decl found"); |
| 5678 | if (D->isInvalidDecl()) return QualType(); |
| 5679 | |
| 5680 | TypeDecl *Ty; |
| 5681 | if (isa<UsingDecl>(D)) { |
| 5682 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5683 | assert(Using->isTypeName() && |
| 5684 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5685 | |
| 5686 | // A valid resolved using typename decl points to exactly one type decl. |
| 5687 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5688 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5689 | |
| 5690 | } else { |
| 5691 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5692 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5693 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5694 | } |
| 5695 | |
| 5696 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5697 | } |
| 5698 | |
| 5699 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5700 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5701 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5702 | } |
| 5703 | |
| 5704 | template<typename Derived> |
| 5705 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5706 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5707 | } |
| 5708 | |
| 5709 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5710 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5711 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5712 | } |
| 5713 | |
| 5714 | template<typename Derived> |
| 5715 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5716 | TemplateName Template, |
| 5717 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5718 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5719 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5720 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5721 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5722 | template<typename Derived> |
| 5723 | NestedNameSpecifier * |
| 5724 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5725 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5726 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5727 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5728 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5729 | CXXScopeSpec SS; |
| 5730 | // FIXME: The source location information is all wrong. |
| 5731 | SS.setRange(Range); |
| 5732 | SS.setScopeRep(Prefix); |
| 5733 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5734 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5735 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5736 | ObjectType, |
| 5737 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5738 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | template<typename Derived> |
| 5742 | NestedNameSpecifier * |
| 5743 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5744 | SourceRange Range, |
| 5745 | NamespaceDecl *NS) { |
| 5746 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5747 | } |
| 5748 | |
| 5749 | template<typename Derived> |
| 5750 | NestedNameSpecifier * |
| 5751 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5752 | SourceRange Range, |
| 5753 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5754 | QualType T) { |
| 5755 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5756 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5757 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5758 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5759 | T.getTypePtr()); |
| 5760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5761 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5762 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5763 | return 0; |
| 5764 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5765 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5766 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5767 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5768 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5769 | bool TemplateKW, |
| 5770 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5771 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5772 | Template); |
| 5773 | } |
| 5774 | |
| 5775 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5776 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5777 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5778 | const IdentifierInfo &II, |
| 5779 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5780 | CXXScopeSpec SS; |
| 5781 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5782 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5783 | UnqualifiedId Name; |
| 5784 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5785 | return getSema().ActOnDependentTemplateName( |
| 5786 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5787 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5788 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5789 | ObjectType.getAsOpaquePtr(), |
| 5790 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5791 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5792 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5793 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5794 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5795 | TemplateName |
| 5796 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5797 | OverloadedOperatorKind Operator, |
| 5798 | QualType ObjectType) { |
| 5799 | CXXScopeSpec SS; |
| 5800 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5801 | SS.setScopeRep(Qualifier); |
| 5802 | UnqualifiedId Name; |
| 5803 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5804 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5805 | Operator, SymbolLocations); |
| 5806 | return getSema().ActOnDependentTemplateName( |
| 5807 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5808 | SS, |
| 5809 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5810 | ObjectType.getAsOpaquePtr(), |
| 5811 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5812 | .template getAsVal<TemplateName>(); |
| 5813 | } |
| 5814 | |
| 5815 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5816 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5817 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5818 | SourceLocation OpLoc, |
| 5819 | ExprArg Callee, |
| 5820 | ExprArg First, |
| 5821 | ExprArg Second) { |
| 5822 | Expr *FirstExpr = (Expr *)First.get(); |
| 5823 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5824 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5825 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5826 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5827 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5828 | if (Op == OO_Subscript) { |
| 5829 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5830 | !SecondExpr->getType()->isOverloadableType()) |
| 5831 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5832 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5833 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5834 | } else if (Op == OO_Arrow) { |
| 5835 | // -> is never a builtin operation. |
| 5836 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5837 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5838 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5839 | // The argument is not of overloadable type, so try to create a |
| 5840 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5841 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5842 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5844 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5845 | } |
| 5846 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5847 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5848 | !SecondExpr->getType()->isOverloadableType()) { |
| 5849 | // Neither of the arguments is an overloadable type, so try to |
| 5850 | // create a built-in binary operation. |
| 5851 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5852 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5853 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5854 | if (Result.isInvalid()) |
| 5855 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5856 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5857 | First.release(); |
| 5858 | Second.release(); |
| 5859 | return move(Result); |
| 5860 | } |
| 5861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5862 | |
| 5863 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5864 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5865 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5866 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5867 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5868 | assert(ULE->requiresADL()); |
| 5869 | |
| 5870 | // FIXME: Do we have to check |
| 5871 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5872 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5873 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5874 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5876 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5877 | // Add any functions found via argument-dependent lookup. |
| 5878 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5879 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5880 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5881 | // Create the overloaded operator invocation for unary operators. |
| 5882 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5883 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5884 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5885 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5886 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5887 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5888 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5889 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5890 | OpLoc, |
| 5891 | move(First), |
| 5892 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5893 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5894 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5895 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5896 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5897 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5898 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5899 | if (Result.isInvalid()) |
| 5900 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5901 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5902 | First.release(); |
| 5903 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5904 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5905 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5906 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5907 | template<typename Derived> |
| 5908 | Sema::OwningExprResult |
| 5909 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 5910 | SourceLocation OperatorLoc, |
| 5911 | bool isArrow, |
| 5912 | NestedNameSpecifier *Qualifier, |
| 5913 | SourceRange QualifierRange, |
| 5914 | TypeSourceInfo *ScopeType, |
| 5915 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5916 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5917 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5918 | CXXScopeSpec SS; |
| 5919 | if (Qualifier) { |
| 5920 | SS.setRange(QualifierRange); |
| 5921 | SS.setScopeRep(Qualifier); |
| 5922 | } |
| 5923 | |
| 5924 | Expr *BaseE = (Expr *)Base.get(); |
| 5925 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5926 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5927 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 5928 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 5929 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 5930 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5931 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 5932 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 5933 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5934 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5935 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5936 | /*FIXME?*/true); |
| 5937 | } |
| 5938 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5939 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5940 | DeclarationName Name |
| 5941 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 5942 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 5943 | |
| 5944 | // FIXME: the ScopeType should be tacked onto SS. |
| 5945 | |
| 5946 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 5947 | OperatorLoc, isArrow, |
| 5948 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5949 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5950 | /*TemplateArgs*/ 0); |
| 5951 | } |
| 5952 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5953 | } // end namespace clang |
| 5954 | |
| 5955 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |