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 | /// |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 540 | /// By default, builds a new DependentNameType 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. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 543 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 544 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | if (NNS->isDependent()) { |
| 546 | CXXScopeSpec SS; |
| 547 | SS.setScopeRep(NNS); |
| 548 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 549 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 550 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 553 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 554 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 556 | |
| 557 | /// \brief Build a new typename type that refers to an identifier. |
| 558 | /// |
| 559 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 561 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 562 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 563 | NestedNameSpecifier *NNS, |
| 564 | const IdentifierInfo *Id, |
| 565 | SourceRange SR) { |
| 566 | // FIXME: Handle elaborated-type-specifiers separately. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 567 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 568 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 570 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 571 | /// identifier that names the next step in the nested-name-specifier. |
| 572 | /// |
| 573 | /// By default, performs semantic analysis when building the new |
| 574 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 575 | /// different behavior. |
| 576 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 577 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 578 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 579 | QualType ObjectType, |
| 580 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 581 | |
| 582 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 583 | /// namespace named in the next step in the nested-name-specifier. |
| 584 | /// |
| 585 | /// By default, performs semantic analysis when building the new |
| 586 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 587 | /// different behavior. |
| 588 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 589 | SourceRange Range, |
| 590 | NamespaceDecl *NS); |
| 591 | |
| 592 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 593 | /// type named in the next step in the nested-name-specifier. |
| 594 | /// |
| 595 | /// By default, performs semantic analysis when building the new |
| 596 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 597 | /// different behavior. |
| 598 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 599 | SourceRange Range, |
| 600 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 601 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 602 | |
| 603 | /// \brief Build a new template name given a nested name specifier, a flag |
| 604 | /// indicating whether the "template" keyword was provided, and the template |
| 605 | /// that the template name refers to. |
| 606 | /// |
| 607 | /// By default, builds the new template name directly. Subclasses may override |
| 608 | /// this routine to provide different behavior. |
| 609 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 610 | bool TemplateKW, |
| 611 | TemplateDecl *Template); |
| 612 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 613 | /// \brief Build a new template name given a nested name specifier and the |
| 614 | /// name that is referred to as a template. |
| 615 | /// |
| 616 | /// By default, performs semantic analysis to determine whether the name can |
| 617 | /// be resolved to a specific template, then builds the appropriate kind of |
| 618 | /// template name. Subclasses may override this routine to provide different |
| 619 | /// behavior. |
| 620 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 621 | const IdentifierInfo &II, |
| 622 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 624 | /// \brief Build a new template name given a nested name specifier and the |
| 625 | /// overloaded operator name that is referred to as a template. |
| 626 | /// |
| 627 | /// By default, performs semantic analysis to determine whether the name can |
| 628 | /// be resolved to a specific template, then builds the appropriate kind of |
| 629 | /// template name. Subclasses may override this routine to provide different |
| 630 | /// behavior. |
| 631 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 632 | OverloadedOperatorKind Operator, |
| 633 | QualType ObjectType); |
| 634 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 635 | /// \brief Build a new compound statement. |
| 636 | /// |
| 637 | /// By default, performs semantic analysis to build the new statement. |
| 638 | /// Subclasses may override this routine to provide different behavior. |
| 639 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 640 | MultiStmtArg Statements, |
| 641 | SourceLocation RBraceLoc, |
| 642 | bool IsStmtExpr) { |
| 643 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 644 | IsStmtExpr); |
| 645 | } |
| 646 | |
| 647 | /// \brief Build a new case statement. |
| 648 | /// |
| 649 | /// By default, performs semantic analysis to build the new statement. |
| 650 | /// Subclasses may override this routine to provide different behavior. |
| 651 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 652 | ExprArg LHS, |
| 653 | SourceLocation EllipsisLoc, |
| 654 | ExprArg RHS, |
| 655 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 657 | ColonLoc); |
| 658 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 660 | /// \brief Attach the body to a new case statement. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis to build the new statement. |
| 663 | /// Subclasses may override this routine to provide different behavior. |
| 664 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 665 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 666 | return move(S); |
| 667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 668 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 669 | /// \brief Build a new default statement. |
| 670 | /// |
| 671 | /// By default, performs semantic analysis to build the new statement. |
| 672 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 673 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 674 | SourceLocation ColonLoc, |
| 675 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 677 | /*CurScope=*/0); |
| 678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 680 | /// \brief Build a new label statement. |
| 681 | /// |
| 682 | /// By default, performs semantic analysis to build the new statement. |
| 683 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 685 | IdentifierInfo *Id, |
| 686 | SourceLocation ColonLoc, |
| 687 | StmtArg SubStmt) { |
| 688 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 689 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 691 | /// \brief Build a new "if" statement. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis to build the new statement. |
| 694 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 696 | VarDecl *CondVar, StmtArg Then, |
| 697 | SourceLocation ElseLoc, StmtArg Else) { |
| 698 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 699 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 702 | /// \brief Start building a new switch statement. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis to build the new statement. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 706 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 707 | VarDecl *CondVar) { |
| 708 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 711 | /// \brief Attach the body to the switch statement. |
| 712 | /// |
| 713 | /// By default, performs semantic analysis to build the new statement. |
| 714 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 716 | StmtArg Switch, StmtArg Body) { |
| 717 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 718 | move(Body)); |
| 719 | } |
| 720 | |
| 721 | /// \brief Build a new while statement. |
| 722 | /// |
| 723 | /// By default, performs semantic analysis to build the new statement. |
| 724 | /// Subclasses may override this routine to provide different behavior. |
| 725 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 726 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 727 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 728 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 729 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 730 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | /// \brief Build a new do-while statement. |
| 734 | /// |
| 735 | /// By default, performs semantic analysis to build the new statement. |
| 736 | /// Subclasses may override this routine to provide different behavior. |
| 737 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 738 | SourceLocation WhileLoc, |
| 739 | SourceLocation LParenLoc, |
| 740 | ExprArg Cond, |
| 741 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 743 | move(Cond), RParenLoc); |
| 744 | } |
| 745 | |
| 746 | /// \brief Build a new for statement. |
| 747 | /// |
| 748 | /// By default, performs semantic analysis to build the new statement. |
| 749 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 751 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 752 | StmtArg Init, Sema::FullExprArg Cond, |
| 753 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 754 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 755 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 756 | DeclPtrTy::make(CondVar), |
| 757 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 760 | /// \brief Build a new goto statement. |
| 761 | /// |
| 762 | /// By default, performs semantic analysis to build the new statement. |
| 763 | /// Subclasses may override this routine to provide different behavior. |
| 764 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 765 | SourceLocation LabelLoc, |
| 766 | LabelStmt *Label) { |
| 767 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 768 | } |
| 769 | |
| 770 | /// \brief Build a new indirect goto statement. |
| 771 | /// |
| 772 | /// By default, performs semantic analysis to build the new statement. |
| 773 | /// Subclasses may override this routine to provide different behavior. |
| 774 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 775 | SourceLocation StarLoc, |
| 776 | ExprArg Target) { |
| 777 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 778 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 780 | /// \brief Build a new return statement. |
| 781 | /// |
| 782 | /// By default, performs semantic analysis to build the new statement. |
| 783 | /// Subclasses may override this routine to provide different behavior. |
| 784 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 785 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 787 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 789 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 790 | /// \brief Build a new declaration statement. |
| 791 | /// |
| 792 | /// By default, performs semantic analysis to build the new statement. |
| 793 | /// Subclasses may override this routine to provide different behavior. |
| 794 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 795 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 796 | SourceLocation EndLoc) { |
| 797 | return getSema().Owned( |
| 798 | new (getSema().Context) DeclStmt( |
| 799 | DeclGroupRef::Create(getSema().Context, |
| 800 | Decls, NumDecls), |
| 801 | StartLoc, EndLoc)); |
| 802 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 804 | /// \brief Build a new inline asm statement. |
| 805 | /// |
| 806 | /// By default, performs semantic analysis to build the new statement. |
| 807 | /// Subclasses may override this routine to provide different behavior. |
| 808 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 809 | bool IsSimple, |
| 810 | bool IsVolatile, |
| 811 | unsigned NumOutputs, |
| 812 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 813 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 814 | MultiExprArg Constraints, |
| 815 | MultiExprArg Exprs, |
| 816 | ExprArg AsmString, |
| 817 | MultiExprArg Clobbers, |
| 818 | SourceLocation RParenLoc, |
| 819 | bool MSAsm) { |
| 820 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 821 | NumInputs, Names, move(Constraints), |
| 822 | move(Exprs), move(AsmString), move(Clobbers), |
| 823 | RParenLoc, MSAsm); |
| 824 | } |
| 825 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 826 | /// \brief Build a new C++ exception declaration. |
| 827 | /// |
| 828 | /// By default, performs semantic analysis to build the new decaration. |
| 829 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 831 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 832 | IdentifierInfo *Name, |
| 833 | SourceLocation Loc, |
| 834 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 836 | TypeRange); |
| 837 | } |
| 838 | |
| 839 | /// \brief Build a new C++ catch statement. |
| 840 | /// |
| 841 | /// By default, performs semantic analysis to build the new statement. |
| 842 | /// Subclasses may override this routine to provide different behavior. |
| 843 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 844 | VarDecl *ExceptionDecl, |
| 845 | StmtArg Handler) { |
| 846 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 847 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 848 | Handler.takeAs<Stmt>())); |
| 849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 850 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 851 | /// \brief Build a new C++ try statement. |
| 852 | /// |
| 853 | /// By default, performs semantic analysis to build the new statement. |
| 854 | /// Subclasses may override this routine to provide different behavior. |
| 855 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 856 | StmtArg TryBlock, |
| 857 | MultiStmtArg Handlers) { |
| 858 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 859 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 861 | /// \brief Build a new expression that references a declaration. |
| 862 | /// |
| 863 | /// By default, performs semantic analysis to build the new expression. |
| 864 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 865 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 866 | LookupResult &R, |
| 867 | bool RequiresADL) { |
| 868 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /// \brief Build a new expression that references a declaration. |
| 873 | /// |
| 874 | /// By default, performs semantic analysis to build the new expression. |
| 875 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 876 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 877 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 878 | ValueDecl *VD, SourceLocation Loc, |
| 879 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 880 | CXXScopeSpec SS; |
| 881 | SS.setScopeRep(Qualifier); |
| 882 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 883 | |
| 884 | // FIXME: loses template args. |
| 885 | |
| 886 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 887 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 888 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 889 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | /// By default, performs semantic analysis to build the new expression. |
| 892 | /// Subclasses may override this routine to provide different behavior. |
| 893 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 894 | SourceLocation RParen) { |
| 895 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 896 | } |
| 897 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 898 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 899 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 900 | /// By default, performs semantic analysis to build the new expression. |
| 901 | /// Subclasses may override this routine to provide different behavior. |
| 902 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 903 | SourceLocation OperatorLoc, |
| 904 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 905 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 906 | SourceRange QualifierRange, |
| 907 | TypeSourceInfo *ScopeType, |
| 908 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 909 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 910 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 912 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 914 | /// By default, performs semantic analysis to build the new expression. |
| 915 | /// Subclasses may override this routine to provide different behavior. |
| 916 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 917 | UnaryOperator::Opcode Opc, |
| 918 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 919 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 922 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 923 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 924 | /// By default, performs semantic analysis to build the new expression. |
| 925 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 926 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 927 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 929 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 932 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 933 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 935 | /// By default, performs semantic analysis to build the new expression. |
| 936 | /// Subclasses may override this routine to provide different behavior. |
| 937 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 938 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 940 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 941 | OpLoc, isSizeOf, R); |
| 942 | if (Result.isInvalid()) |
| 943 | return getSema().ExprError(); |
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 | SubExpr.release(); |
| 946 | return move(Result); |
| 947 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 949 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 950 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 951 | /// By default, performs semantic analysis to build the new expression. |
| 952 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 954 | SourceLocation LBracketLoc, |
| 955 | ExprArg RHS, |
| 956 | SourceLocation RBracketLoc) { |
| 957 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 959 | RBracketLoc); |
| 960 | } |
| 961 | |
| 962 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 964 | /// By default, performs semantic analysis to build the new expression. |
| 965 | /// Subclasses may override this routine to provide different behavior. |
| 966 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 967 | MultiExprArg Args, |
| 968 | SourceLocation *CommaLocs, |
| 969 | SourceLocation RParenLoc) { |
| 970 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 971 | move(Args), CommaLocs, RParenLoc); |
| 972 | } |
| 973 | |
| 974 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 976 | /// By default, performs semantic analysis to build the new expression. |
| 977 | /// Subclasses may override this routine to provide different behavior. |
| 978 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 979 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 980 | NestedNameSpecifier *Qualifier, |
| 981 | SourceRange QualifierRange, |
| 982 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 983 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 984 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 985 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 986 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 987 | if (!Member->getDeclName()) { |
| 988 | // We have a reference to an unnamed field. |
| 989 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 991 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 992 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 993 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 994 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 995 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 997 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 998 | Member, MemberLoc, |
| 999 | cast<FieldDecl>(Member)->getType()); |
| 1000 | return getSema().Owned(ME); |
| 1001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1003 | CXXScopeSpec SS; |
| 1004 | if (Qualifier) { |
| 1005 | SS.setRange(QualifierRange); |
| 1006 | SS.setScopeRep(Qualifier); |
| 1007 | } |
| 1008 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1009 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1010 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1011 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1012 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1013 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1014 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1015 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1016 | R.resolveKind(); |
| 1017 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1018 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1019 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1020 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1021 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1022 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1024 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1026 | /// By default, performs semantic analysis to build the new expression. |
| 1027 | /// Subclasses may override this routine to provide different behavior. |
| 1028 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1029 | BinaryOperator::Opcode Opc, |
| 1030 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1031 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1032 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// By default, performs semantic analysis to build the new expression. |
| 1038 | /// Subclasses may override this routine to provide different behavior. |
| 1039 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1040 | SourceLocation QuestionLoc, |
| 1041 | ExprArg LHS, |
| 1042 | SourceLocation ColonLoc, |
| 1043 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1044 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | move(LHS), move(RHS)); |
| 1046 | } |
| 1047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1048 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | /// By default, performs semantic analysis to build the new expression. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1052 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1053 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | SourceLocation RParenLoc, |
| 1055 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1056 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1057 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1060 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | /// By default, performs semantic analysis to build the new expression. |
| 1063 | /// Subclasses may override this routine to provide different behavior. |
| 1064 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1065 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1066 | SourceLocation RParenLoc, |
| 1067 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1068 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1069 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1072 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1073 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1074 | /// By default, performs semantic analysis to build the new expression. |
| 1075 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1076 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1077 | SourceLocation OpLoc, |
| 1078 | SourceLocation AccessorLoc, |
| 1079 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1080 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1081 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1082 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1083 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1084 | OpLoc, /*IsArrow*/ false, |
| 1085 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1086 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1087 | AccessorLoc, |
| 1088 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1091 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | /// By default, performs semantic analysis to build the new expression. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
| 1095 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1096 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1097 | SourceLocation RBraceLoc, |
| 1098 | QualType ResultTy) { |
| 1099 | OwningExprResult Result |
| 1100 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1101 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1102 | return move(Result); |
| 1103 | |
| 1104 | // Patch in the result type we were given, which may have been computed |
| 1105 | // when the initial InitListExpr was built. |
| 1106 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1107 | ILE->setType(ResultTy); |
| 1108 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1110 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1111 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1113 | /// By default, performs semantic analysis to build the new expression. |
| 1114 | /// Subclasses may override this routine to provide different behavior. |
| 1115 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1116 | MultiExprArg ArrayExprs, |
| 1117 | SourceLocation EqualOrColonLoc, |
| 1118 | bool GNUSyntax, |
| 1119 | ExprArg Init) { |
| 1120 | OwningExprResult Result |
| 1121 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1122 | move(Init)); |
| 1123 | if (Result.isInvalid()) |
| 1124 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1125 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1126 | ArrayExprs.release(); |
| 1127 | return move(Result); |
| 1128 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1132 | /// By default, builds the implicit value initialization without performing |
| 1133 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1134 | /// different behavior. |
| 1135 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1136 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1137 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | /// By default, performs semantic analysis to build the new expression. |
| 1142 | /// Subclasses may override this routine to provide different behavior. |
| 1143 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1144 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1146 | RParenLoc); |
| 1147 | } |
| 1148 | |
| 1149 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1151 | /// By default, performs semantic analysis to build the new expression. |
| 1152 | /// Subclasses may override this routine to provide different behavior. |
| 1153 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1154 | MultiExprArg SubExprs, |
| 1155 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1156 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1157 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1160 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | /// |
| 1162 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1163 | /// rather than attempting to map the label statement itself. |
| 1164 | /// Subclasses may override this routine to provide different behavior. |
| 1165 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1166 | SourceLocation LabelLoc, |
| 1167 | LabelStmt *Label) { |
| 1168 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1169 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1171 | /// \brief Build a new GNU statement expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1174 | /// Subclasses may override this routine to provide different behavior. |
| 1175 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1176 | StmtArg SubStmt, |
| 1177 | SourceLocation RParenLoc) { |
| 1178 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1179 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1181 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1182 | /// |
| 1183 | /// By default, performs semantic analysis to build the new expression. |
| 1184 | /// Subclasses may override this routine to provide different behavior. |
| 1185 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1186 | QualType T1, QualType T2, |
| 1187 | SourceLocation RParenLoc) { |
| 1188 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1189 | T1.getAsOpaquePtr(), |
| 1190 | T2.getAsOpaquePtr(), |
| 1191 | RParenLoc); |
| 1192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | /// \brief Build a new __builtin_choose_expr expression. |
| 1195 | /// |
| 1196 | /// By default, performs semantic analysis to build the new expression. |
| 1197 | /// Subclasses may override this routine to provide different behavior. |
| 1198 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1199 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1200 | SourceLocation RParenLoc) { |
| 1201 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1202 | move(Cond), move(LHS), move(RHS), |
| 1203 | RParenLoc); |
| 1204 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | /// \brief Build a new overloaded operator call expression. |
| 1207 | /// |
| 1208 | /// By default, performs semantic analysis to build the new expression. |
| 1209 | /// The semantic analysis provides the behavior of template instantiation, |
| 1210 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1212 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1213 | /// provide different behavior. |
| 1214 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1215 | SourceLocation OpLoc, |
| 1216 | ExprArg Callee, |
| 1217 | ExprArg First, |
| 1218 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | |
| 1220 | /// \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] | 1221 | /// reinterpret_cast. |
| 1222 | /// |
| 1223 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | /// Subclasses may override this routine to provide different behavior. |
| 1226 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1227 | Stmt::StmtClass Class, |
| 1228 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1229 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | SourceLocation RAngleLoc, |
| 1231 | SourceLocation LParenLoc, |
| 1232 | ExprArg SubExpr, |
| 1233 | SourceLocation RParenLoc) { |
| 1234 | switch (Class) { |
| 1235 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1236 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | move(SubExpr), RParenLoc); |
| 1239 | |
| 1240 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1241 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1243 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1246 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | RAngleLoc, LParenLoc, |
| 1248 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1249 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1250 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1251 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1252 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1253 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1254 | move(SubExpr), RParenLoc); |
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 | default: |
| 1257 | assert(false && "Invalid C++ named cast"); |
| 1258 | break; |
| 1259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | return getSema().ExprError(); |
| 1262 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1264 | /// \brief Build a new C++ static_cast expression. |
| 1265 | /// |
| 1266 | /// By default, performs semantic analysis to build the new expression. |
| 1267 | /// Subclasses may override this routine to provide different behavior. |
| 1268 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1269 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1270 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1271 | SourceLocation RAngleLoc, |
| 1272 | SourceLocation LParenLoc, |
| 1273 | ExprArg SubExpr, |
| 1274 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1275 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1276 | TInfo, move(SubExpr), |
| 1277 | SourceRange(LAngleLoc, RAngleLoc), |
| 1278 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | /// \brief Build a new C++ dynamic_cast expression. |
| 1282 | /// |
| 1283 | /// By default, performs semantic analysis to build the new expression. |
| 1284 | /// Subclasses may override this routine to provide different behavior. |
| 1285 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1286 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1287 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1288 | SourceLocation RAngleLoc, |
| 1289 | SourceLocation LParenLoc, |
| 1290 | ExprArg SubExpr, |
| 1291 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1292 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1293 | TInfo, move(SubExpr), |
| 1294 | SourceRange(LAngleLoc, RAngleLoc), |
| 1295 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1299 | /// |
| 1300 | /// By default, performs semantic analysis to build the new expression. |
| 1301 | /// Subclasses may override this routine to provide different behavior. |
| 1302 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1303 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1304 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | SourceLocation RAngleLoc, |
| 1306 | SourceLocation LParenLoc, |
| 1307 | ExprArg SubExpr, |
| 1308 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1309 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1310 | TInfo, move(SubExpr), |
| 1311 | SourceRange(LAngleLoc, RAngleLoc), |
| 1312 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /// \brief Build a new C++ const_cast expression. |
| 1316 | /// |
| 1317 | /// By default, performs semantic analysis to build the new expression. |
| 1318 | /// Subclasses may override this routine to provide different behavior. |
| 1319 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1320 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1321 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1322 | SourceLocation RAngleLoc, |
| 1323 | SourceLocation LParenLoc, |
| 1324 | ExprArg SubExpr, |
| 1325 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1326 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1327 | TInfo, move(SubExpr), |
| 1328 | SourceRange(LAngleLoc, RAngleLoc), |
| 1329 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | /// \brief Build a new C++ functional-style cast expression. |
| 1333 | /// |
| 1334 | /// By default, performs semantic analysis to build the new expression. |
| 1335 | /// Subclasses may override this routine to provide different behavior. |
| 1336 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1337 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | SourceLocation LParenLoc, |
| 1339 | ExprArg SubExpr, |
| 1340 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1341 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1342 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1343 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1345 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | RParenLoc); |
| 1348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | /// \brief Build a new C++ typeid(type) expression. |
| 1351 | /// |
| 1352 | /// By default, performs semantic analysis to build the new expression. |
| 1353 | /// Subclasses may override this routine to provide different behavior. |
| 1354 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1355 | SourceLocation LParenLoc, |
| 1356 | QualType T, |
| 1357 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1358 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1359 | T.getAsOpaquePtr(), RParenLoc); |
| 1360 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1361 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1362 | /// \brief Build a new C++ typeid(expr) expression. |
| 1363 | /// |
| 1364 | /// By default, performs semantic analysis to build the new expression. |
| 1365 | /// Subclasses may override this routine to provide different behavior. |
| 1366 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1367 | SourceLocation LParenLoc, |
| 1368 | ExprArg Operand, |
| 1369 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1370 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1371 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1372 | RParenLoc); |
| 1373 | if (Result.isInvalid()) |
| 1374 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1377 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | /// \brief Build a new C++ "this" expression. |
| 1381 | /// |
| 1382 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1383 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1384 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1386 | QualType ThisType, |
| 1387 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1388 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1389 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1390 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /// \brief Build a new C++ throw expression. |
| 1394 | /// |
| 1395 | /// By default, performs semantic analysis to build the new expression. |
| 1396 | /// Subclasses may override this routine to provide different behavior. |
| 1397 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1398 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1399 | } |
| 1400 | |
| 1401 | /// \brief Build a new C++ default-argument expression. |
| 1402 | /// |
| 1403 | /// By default, builds a new default-argument expression, which does not |
| 1404 | /// require any semantic analysis. Subclasses may override this routine to |
| 1405 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1406 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1407 | ParmVarDecl *Param) { |
| 1408 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1409 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /// \brief Build a new C++ zero-initialization expression. |
| 1413 | /// |
| 1414 | /// By default, performs semantic analysis to build the new expression. |
| 1415 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | SourceLocation LParenLoc, |
| 1418 | QualType T, |
| 1419 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1421 | T.getAsOpaquePtr(), LParenLoc, |
| 1422 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | 0, RParenLoc); |
| 1424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | /// \brief Build a new C++ "new" expression. |
| 1427 | /// |
| 1428 | /// By default, performs semantic analysis to build the new expression. |
| 1429 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1431 | bool UseGlobal, |
| 1432 | SourceLocation PlacementLParen, |
| 1433 | MultiExprArg PlacementArgs, |
| 1434 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | QualType AllocType, |
| 1437 | SourceLocation TypeLoc, |
| 1438 | SourceRange TypeRange, |
| 1439 | ExprArg ArraySize, |
| 1440 | SourceLocation ConstructorLParen, |
| 1441 | MultiExprArg ConstructorArgs, |
| 1442 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1444 | PlacementLParen, |
| 1445 | move(PlacementArgs), |
| 1446 | PlacementRParen, |
| 1447 | ParenTypeId, |
| 1448 | AllocType, |
| 1449 | TypeLoc, |
| 1450 | TypeRange, |
| 1451 | move(ArraySize), |
| 1452 | ConstructorLParen, |
| 1453 | move(ConstructorArgs), |
| 1454 | ConstructorRParen); |
| 1455 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | /// \brief Build a new C++ "delete" expression. |
| 1458 | /// |
| 1459 | /// By default, performs semantic analysis to build the new expression. |
| 1460 | /// Subclasses may override this routine to provide different behavior. |
| 1461 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1462 | bool IsGlobalDelete, |
| 1463 | bool IsArrayForm, |
| 1464 | ExprArg Operand) { |
| 1465 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1466 | move(Operand)); |
| 1467 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1468 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | /// \brief Build a new unary type trait expression. |
| 1470 | /// |
| 1471 | /// By default, performs semantic analysis to build the new expression. |
| 1472 | /// Subclasses may override this routine to provide different behavior. |
| 1473 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1474 | SourceLocation StartLoc, |
| 1475 | SourceLocation LParenLoc, |
| 1476 | QualType T, |
| 1477 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1478 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1479 | T.getAsOpaquePtr(), RParenLoc); |
| 1480 | } |
| 1481 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1482 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1483 | /// expression. |
| 1484 | /// |
| 1485 | /// By default, performs semantic analysis to build the new expression. |
| 1486 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1487 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1488 | SourceRange QualifierRange, |
| 1489 | DeclarationName Name, |
| 1490 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1491 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | CXXScopeSpec SS; |
| 1493 | SS.setRange(QualifierRange); |
| 1494 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1495 | |
| 1496 | if (TemplateArgs) |
| 1497 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1498 | *TemplateArgs); |
| 1499 | |
| 1500 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /// \brief Build a new template-id expression. |
| 1504 | /// |
| 1505 | /// By default, performs semantic analysis to build the new expression. |
| 1506 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1507 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1508 | LookupResult &R, |
| 1509 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1510 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1511 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /// \brief Build a new object-construction expression. |
| 1515 | /// |
| 1516 | /// By default, performs semantic analysis to build the new expression. |
| 1517 | /// Subclasses may override this routine to provide different behavior. |
| 1518 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1519 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1520 | CXXConstructorDecl *Constructor, |
| 1521 | bool IsElidable, |
| 1522 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1523 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1524 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1525 | ConvertedArgs)) |
| 1526 | return getSema().ExprError(); |
| 1527 | |
| 1528 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1529 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | /// \brief Build a new object-construction expression. |
| 1533 | /// |
| 1534 | /// By default, performs semantic analysis to build the new expression. |
| 1535 | /// Subclasses may override this routine to provide different behavior. |
| 1536 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1537 | QualType T, |
| 1538 | SourceLocation LParenLoc, |
| 1539 | MultiExprArg Args, |
| 1540 | SourceLocation *Commas, |
| 1541 | SourceLocation RParenLoc) { |
| 1542 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1543 | T.getAsOpaquePtr(), |
| 1544 | LParenLoc, |
| 1545 | move(Args), |
| 1546 | Commas, |
| 1547 | RParenLoc); |
| 1548 | } |
| 1549 | |
| 1550 | /// \brief Build a new object-construction expression. |
| 1551 | /// |
| 1552 | /// By default, performs semantic analysis to build the new expression. |
| 1553 | /// Subclasses may override this routine to provide different behavior. |
| 1554 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1555 | QualType T, |
| 1556 | SourceLocation LParenLoc, |
| 1557 | MultiExprArg Args, |
| 1558 | SourceLocation *Commas, |
| 1559 | SourceLocation RParenLoc) { |
| 1560 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1561 | /*FIXME*/LParenLoc), |
| 1562 | T.getAsOpaquePtr(), |
| 1563 | LParenLoc, |
| 1564 | move(Args), |
| 1565 | Commas, |
| 1566 | RParenLoc); |
| 1567 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | /// \brief Build a new member reference expression. |
| 1570 | /// |
| 1571 | /// By default, performs semantic analysis to build the new expression. |
| 1572 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1573 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1574 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1575 | bool IsArrow, |
| 1576 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1577 | NestedNameSpecifier *Qualifier, |
| 1578 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1579 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1580 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1581 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1582 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1584 | SS.setRange(QualifierRange); |
| 1585 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1587 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1588 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1589 | SS, FirstQualifierInScope, |
| 1590 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1593 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1594 | /// |
| 1595 | /// By default, performs semantic analysis to build the new expression. |
| 1596 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1597 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1598 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1599 | SourceLocation OperatorLoc, |
| 1600 | bool IsArrow, |
| 1601 | NestedNameSpecifier *Qualifier, |
| 1602 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1603 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1604 | LookupResult &R, |
| 1605 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1606 | CXXScopeSpec SS; |
| 1607 | SS.setRange(QualifierRange); |
| 1608 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1610 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1611 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1612 | SS, FirstQualifierInScope, |
| 1613 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1614 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | /// \brief Build a new Objective-C @encode expression. |
| 1617 | /// |
| 1618 | /// By default, performs semantic analysis to build the new expression. |
| 1619 | /// Subclasses may override this routine to provide different behavior. |
| 1620 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1621 | QualType T, |
| 1622 | SourceLocation RParenLoc) { |
| 1623 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1624 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | |
| 1627 | /// \brief Build a new Objective-C protocol expression. |
| 1628 | /// |
| 1629 | /// By default, performs semantic analysis to build the new expression. |
| 1630 | /// Subclasses may override this routine to provide different behavior. |
| 1631 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1632 | SourceLocation AtLoc, |
| 1633 | SourceLocation ProtoLoc, |
| 1634 | SourceLocation LParenLoc, |
| 1635 | SourceLocation RParenLoc) { |
| 1636 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1637 | Protocol->getIdentifier(), |
| 1638 | AtLoc, |
| 1639 | ProtoLoc, |
| 1640 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | /// \brief Build a new shuffle vector expression. |
| 1645 | /// |
| 1646 | /// By default, performs semantic analysis to build the new expression. |
| 1647 | /// Subclasses may override this routine to provide different behavior. |
| 1648 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1649 | MultiExprArg SubExprs, |
| 1650 | SourceLocation RParenLoc) { |
| 1651 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1653 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1654 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1655 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1656 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | // Build a reference to the __builtin_shufflevector builtin |
| 1659 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1660 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1662 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1663 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | |
| 1665 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | unsigned NumSubExprs = SubExprs.size(); |
| 1667 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1668 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1669 | Subs, NumSubExprs, |
| 1670 | Builtin->getResultType(), |
| 1671 | RParenLoc); |
| 1672 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1673 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1674 | // Type-check the __builtin_shufflevector expression. |
| 1675 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1676 | if (Result.isInvalid()) |
| 1677 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1678 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1682 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1684 | template<typename Derived> |
| 1685 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1686 | if (!S) |
| 1687 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1688 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1689 | switch (S->getStmtClass()) { |
| 1690 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1692 | // Transform individual statement nodes |
| 1693 | #define STMT(Node, Parent) \ |
| 1694 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1695 | #define EXPR(Node, Parent) |
| 1696 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1697 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1698 | // Transform expressions by calling TransformExpr. |
| 1699 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1700 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1701 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1702 | #include "clang/AST/StmtNodes.def" |
| 1703 | { |
| 1704 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1705 | if (E.isInvalid()) |
| 1706 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1707 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1708 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1712 | return SemaRef.Owned(S->Retain()); |
| 1713 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1714 | |
| 1715 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1716 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1717 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | if (!E) |
| 1719 | return SemaRef.Owned(E); |
| 1720 | |
| 1721 | switch (E->getStmtClass()) { |
| 1722 | case Stmt::NoStmtClass: break; |
| 1723 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1724 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1725 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1726 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1727 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1730 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1734 | NestedNameSpecifier * |
| 1735 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1736 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1737 | QualType ObjectType, |
| 1738 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1739 | if (!NNS) |
| 1740 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1742 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1743 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1744 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1745 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1746 | ObjectType, |
| 1747 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1748 | if (!Prefix) |
| 1749 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | |
| 1751 | // 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] | 1752 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1753 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1754 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1757 | switch (NNS->getKind()) { |
| 1758 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1760 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1761 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1762 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1763 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1764 | |
| 1765 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1766 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1767 | ObjectType, |
| 1768 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1770 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1772 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1773 | getDerived().TransformDecl(Range.getBegin(), |
| 1774 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1775 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1776 | Prefix == NNS->getPrefix() && |
| 1777 | NS == NNS->getAsNamespace()) |
| 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 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1781 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1783 | case NestedNameSpecifier::Global: |
| 1784 | // There is no meaningful transformation that one could perform on the |
| 1785 | // global scope. |
| 1786 | return NNS; |
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 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1789 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1790 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1791 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1792 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1793 | if (T.isNull()) |
| 1794 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1795 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1796 | if (!getDerived().AlwaysRebuild() && |
| 1797 | Prefix == NNS->getPrefix() && |
| 1798 | T == QualType(NNS->getAsType(), 0)) |
| 1799 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1800 | |
| 1801 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1802 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1803 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1806 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1807 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1812 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1813 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1814 | SourceLocation Loc, |
| 1815 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1816 | if (!Name) |
| 1817 | return Name; |
| 1818 | |
| 1819 | switch (Name.getNameKind()) { |
| 1820 | case DeclarationName::Identifier: |
| 1821 | case DeclarationName::ObjCZeroArgSelector: |
| 1822 | case DeclarationName::ObjCOneArgSelector: |
| 1823 | case DeclarationName::ObjCMultiArgSelector: |
| 1824 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1825 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1826 | case DeclarationName::CXXUsingDirective: |
| 1827 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1828 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1829 | case DeclarationName::CXXConstructorName: |
| 1830 | case DeclarationName::CXXDestructorName: |
| 1831 | case DeclarationName::CXXConversionFunctionName: { |
| 1832 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1833 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1834 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1835 | if (T.isNull()) |
| 1836 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1838 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1840 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1844 | return DeclarationName(); |
| 1845 | } |
| 1846 | |
| 1847 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1848 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1849 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1850 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1851 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1852 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1855 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1856 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1857 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1858 | if (!NNS) |
| 1859 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1861 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1863 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1864 | if (!TransTemplate) |
| 1865 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1867 | if (!getDerived().AlwaysRebuild() && |
| 1868 | NNS == QTN->getQualifier() && |
| 1869 | TransTemplate == Template) |
| 1870 | return Name; |
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 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1873 | TransTemplate); |
| 1874 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1876 | // These should be getting filtered out before they make it into the AST. |
| 1877 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | } |
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 (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1881 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1882 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1883 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1884 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1885 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1886 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1888 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1889 | NNS == DTN->getQualifier() && |
| 1890 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1891 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1893 | if (DTN->isIdentifier()) |
| 1894 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1895 | ObjectType); |
| 1896 | |
| 1897 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1898 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1900 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1901 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1902 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1903 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1904 | if (!TransTemplate) |
| 1905 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1906 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1907 | if (!getDerived().AlwaysRebuild() && |
| 1908 | TransTemplate == Template) |
| 1909 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1910 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1911 | return TemplateName(TransTemplate); |
| 1912 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1913 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1914 | // These should be getting filtered out before they reach the AST. |
| 1915 | assert(false && "overloaded function decl survived to here"); |
| 1916 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1920 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1921 | const TemplateArgument &Arg, |
| 1922 | TemplateArgumentLoc &Output) { |
| 1923 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1924 | switch (Arg.getKind()) { |
| 1925 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1926 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | |
| 1929 | case TemplateArgument::Type: |
| 1930 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1931 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1932 | |
| 1933 | break; |
| 1934 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1935 | case TemplateArgument::Template: |
| 1936 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1937 | break; |
| 1938 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1939 | case TemplateArgument::Expression: |
| 1940 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1941 | break; |
| 1942 | |
| 1943 | case TemplateArgument::Declaration: |
| 1944 | case TemplateArgument::Integral: |
| 1945 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1946 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1947 | break; |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | template<typename Derived> |
| 1952 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1953 | const TemplateArgumentLoc &Input, |
| 1954 | TemplateArgumentLoc &Output) { |
| 1955 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1956 | switch (Arg.getKind()) { |
| 1957 | case TemplateArgument::Null: |
| 1958 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1959 | Output = Input; |
| 1960 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1962 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1963 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1964 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1965 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1966 | |
| 1967 | DI = getDerived().TransformType(DI); |
| 1968 | if (!DI) return true; |
| 1969 | |
| 1970 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1971 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1973 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1974 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1975 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1976 | DeclarationName Name; |
| 1977 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1978 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1979 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1980 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1981 | if (!D) return true; |
| 1982 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1983 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1984 | if (SourceExpr) { |
| 1985 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1986 | Action::Unevaluated); |
| 1987 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1988 | if (E.isInvalid()) |
| 1989 | SourceExpr = NULL; |
| 1990 | else { |
| 1991 | SourceExpr = E.takeAs<Expr>(); |
| 1992 | SourceExpr->Retain(); |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1997 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2000 | case TemplateArgument::Template: { |
| 2001 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2002 | TemplateName Template |
| 2003 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2004 | if (Template.isNull()) |
| 2005 | return true; |
| 2006 | |
| 2007 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2008 | Input.getTemplateQualifierRange(), |
| 2009 | Input.getTemplateNameLoc()); |
| 2010 | return false; |
| 2011 | } |
| 2012 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2013 | case TemplateArgument::Expression: { |
| 2014 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2016 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2018 | Expr *InputExpr = Input.getSourceExpression(); |
| 2019 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2020 | |
| 2021 | Sema::OwningExprResult E |
| 2022 | = getDerived().TransformExpr(InputExpr); |
| 2023 | if (E.isInvalid()) return true; |
| 2024 | |
| 2025 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2026 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2027 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2028 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2029 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2030 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2031 | case TemplateArgument::Pack: { |
| 2032 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2033 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2035 | AEnd = Arg.pack_end(); |
| 2036 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2037 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2038 | // FIXME: preserve source information here when we start |
| 2039 | // caring about parameter packs. |
| 2040 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2041 | TemplateArgumentLoc InputArg; |
| 2042 | TemplateArgumentLoc OutputArg; |
| 2043 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2044 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2045 | return true; |
| 2046 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2047 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2048 | } |
| 2049 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2050 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2051 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2052 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2053 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2054 | } |
| 2055 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2056 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2057 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2058 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2061 | //===----------------------------------------------------------------------===// |
| 2062 | // Type transformation |
| 2063 | //===----------------------------------------------------------------------===// |
| 2064 | |
| 2065 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2066 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2067 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2068 | if (getDerived().AlreadyTransformed(T)) |
| 2069 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2071 | // Temporary workaround. All of these transformations should |
| 2072 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2073 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2074 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2075 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2076 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2077 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2078 | if (!NewDI) |
| 2079 | return QualType(); |
| 2080 | |
| 2081 | return NewDI->getType(); |
| 2082 | } |
| 2083 | |
| 2084 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2085 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2086 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2087 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2088 | return DI; |
| 2089 | |
| 2090 | TypeLocBuilder TLB; |
| 2091 | |
| 2092 | TypeLoc TL = DI->getTypeLoc(); |
| 2093 | TLB.reserve(TL.getFullDataSize()); |
| 2094 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2095 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2096 | if (Result.isNull()) |
| 2097 | return 0; |
| 2098 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2099 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | template<typename Derived> |
| 2103 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2104 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2105 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2106 | switch (T.getTypeLocClass()) { |
| 2107 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2108 | #define TYPELOC(CLASS, PARENT) \ |
| 2109 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2110 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2111 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2112 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2115 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2116 | return QualType(); |
| 2117 | } |
| 2118 | |
| 2119 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2120 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2121 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2122 | /// types). This is the right thing for template instantiation, but |
| 2123 | /// probably not for other clients. |
| 2124 | template<typename Derived> |
| 2125 | QualType |
| 2126 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2127 | QualifiedTypeLoc T, |
| 2128 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2129 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2130 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2131 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2132 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2133 | if (Result.isNull()) |
| 2134 | return QualType(); |
| 2135 | |
| 2136 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2137 | // FIXME: this is the right thing for template instantiation, but |
| 2138 | // probably not for other clients. |
| 2139 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2140 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2141 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2142 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2143 | |
| 2144 | TLB.push<QualifiedTypeLoc>(Result); |
| 2145 | |
| 2146 | // No location information to preserve. |
| 2147 | |
| 2148 | return Result; |
| 2149 | } |
| 2150 | |
| 2151 | template <class TyLoc> static inline |
| 2152 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2153 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2154 | NewT.setNameLoc(T.getNameLoc()); |
| 2155 | return T.getType(); |
| 2156 | } |
| 2157 | |
| 2158 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2159 | // the equivalent template version work. |
| 2160 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2161 | QualType PointeeType \ |
| 2162 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2163 | if (PointeeType.isNull()) \ |
| 2164 | return QualType(); \ |
| 2165 | \ |
| 2166 | QualType Result = TL.getType(); \ |
| 2167 | if (getDerived().AlwaysRebuild() || \ |
| 2168 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2169 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2170 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2171 | if (Result.isNull()) \ |
| 2172 | return QualType(); \ |
| 2173 | } \ |
| 2174 | \ |
| 2175 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2176 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2177 | \ |
| 2178 | return Result; \ |
| 2179 | } while(0) |
| 2180 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2181 | template<typename Derived> |
| 2182 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2183 | BuiltinTypeLoc T, |
| 2184 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2185 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2186 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2187 | if (T.needsExtraLocalData()) |
| 2188 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2189 | return T.getType(); |
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>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2194 | ComplexTypeLoc T, |
| 2195 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2196 | // FIXME: recurse? |
| 2197 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2200 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2201 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2202 | PointerTypeLoc TL, |
| 2203 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2204 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2205 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2206 | |
| 2207 | template<typename Derived> |
| 2208 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2209 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2210 | BlockPointerTypeLoc TL, |
| 2211 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2212 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2215 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2216 | /// don't care whether the type itself is an l-value type or an r-value |
| 2217 | /// type; we only care if the type was *written* as an l-value type |
| 2218 | /// or an r-value type. |
| 2219 | template<typename Derived> |
| 2220 | QualType |
| 2221 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2222 | ReferenceTypeLoc TL, |
| 2223 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2224 | const ReferenceType *T = TL.getTypePtr(); |
| 2225 | |
| 2226 | // Note that this works with the pointee-as-written. |
| 2227 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2228 | if (PointeeType.isNull()) |
| 2229 | return QualType(); |
| 2230 | |
| 2231 | QualType Result = TL.getType(); |
| 2232 | if (getDerived().AlwaysRebuild() || |
| 2233 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2234 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2235 | T->isSpelledAsLValue(), |
| 2236 | TL.getSigilLoc()); |
| 2237 | if (Result.isNull()) |
| 2238 | return QualType(); |
| 2239 | } |
| 2240 | |
| 2241 | // r-value references can be rebuilt as l-value references. |
| 2242 | ReferenceTypeLoc NewTL; |
| 2243 | if (isa<LValueReferenceType>(Result)) |
| 2244 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2245 | else |
| 2246 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2247 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2248 | |
| 2249 | return Result; |
| 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>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2255 | LValueReferenceTypeLoc TL, |
| 2256 | QualType ObjectType) { |
| 2257 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2260 | template<typename Derived> |
| 2261 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2262 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2263 | RValueReferenceTypeLoc TL, |
| 2264 | QualType ObjectType) { |
| 2265 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2267 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2268 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2269 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2270 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2271 | MemberPointerTypeLoc TL, |
| 2272 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2273 | MemberPointerType *T = TL.getTypePtr(); |
| 2274 | |
| 2275 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2276 | if (PointeeType.isNull()) |
| 2277 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2279 | // TODO: preserve source information for this. |
| 2280 | QualType ClassType |
| 2281 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2282 | if (ClassType.isNull()) |
| 2283 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2285 | QualType Result = TL.getType(); |
| 2286 | if (getDerived().AlwaysRebuild() || |
| 2287 | PointeeType != T->getPointeeType() || |
| 2288 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2289 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2290 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2291 | if (Result.isNull()) |
| 2292 | return QualType(); |
| 2293 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2294 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2295 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2296 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2297 | |
| 2298 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2301 | template<typename Derived> |
| 2302 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2303 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2304 | ConstantArrayTypeLoc TL, |
| 2305 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2306 | ConstantArrayType *T = TL.getTypePtr(); |
| 2307 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2308 | if (ElementType.isNull()) |
| 2309 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2310 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2311 | QualType Result = TL.getType(); |
| 2312 | if (getDerived().AlwaysRebuild() || |
| 2313 | ElementType != T->getElementType()) { |
| 2314 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2315 | T->getSizeModifier(), |
| 2316 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2317 | T->getIndexTypeCVRQualifiers(), |
| 2318 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2319 | if (Result.isNull()) |
| 2320 | return QualType(); |
| 2321 | } |
| 2322 | |
| 2323 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2324 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2325 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2326 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2327 | Expr *Size = TL.getSizeExpr(); |
| 2328 | if (Size) { |
| 2329 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2330 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2331 | } |
| 2332 | NewTL.setSizeExpr(Size); |
| 2333 | |
| 2334 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2335 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2337 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2338 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2339 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2340 | IncompleteArrayTypeLoc TL, |
| 2341 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2342 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2343 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2344 | if (ElementType.isNull()) |
| 2345 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2346 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2347 | QualType Result = TL.getType(); |
| 2348 | if (getDerived().AlwaysRebuild() || |
| 2349 | ElementType != T->getElementType()) { |
| 2350 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2351 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2352 | T->getIndexTypeCVRQualifiers(), |
| 2353 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2354 | if (Result.isNull()) |
| 2355 | return QualType(); |
| 2356 | } |
| 2357 | |
| 2358 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2359 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2360 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2361 | NewTL.setSizeExpr(0); |
| 2362 | |
| 2363 | return Result; |
| 2364 | } |
| 2365 | |
| 2366 | template<typename Derived> |
| 2367 | QualType |
| 2368 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2369 | VariableArrayTypeLoc TL, |
| 2370 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2371 | VariableArrayType *T = TL.getTypePtr(); |
| 2372 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2373 | if (ElementType.isNull()) |
| 2374 | return QualType(); |
| 2375 | |
| 2376 | // Array bounds are not potentially evaluated contexts |
| 2377 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2378 | |
| 2379 | Sema::OwningExprResult SizeResult |
| 2380 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2381 | if (SizeResult.isInvalid()) |
| 2382 | return QualType(); |
| 2383 | |
| 2384 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2385 | |
| 2386 | QualType Result = TL.getType(); |
| 2387 | if (getDerived().AlwaysRebuild() || |
| 2388 | ElementType != T->getElementType() || |
| 2389 | Size != T->getSizeExpr()) { |
| 2390 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2391 | T->getSizeModifier(), |
| 2392 | move(SizeResult), |
| 2393 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2394 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2395 | if (Result.isNull()) |
| 2396 | return QualType(); |
| 2397 | } |
| 2398 | else SizeResult.take(); |
| 2399 | |
| 2400 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2401 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2402 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2403 | NewTL.setSizeExpr(Size); |
| 2404 | |
| 2405 | return Result; |
| 2406 | } |
| 2407 | |
| 2408 | template<typename Derived> |
| 2409 | QualType |
| 2410 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2411 | DependentSizedArrayTypeLoc TL, |
| 2412 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2413 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2414 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2415 | if (ElementType.isNull()) |
| 2416 | return QualType(); |
| 2417 | |
| 2418 | // Array bounds are not potentially evaluated contexts |
| 2419 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2420 | |
| 2421 | Sema::OwningExprResult SizeResult |
| 2422 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2423 | if (SizeResult.isInvalid()) |
| 2424 | return QualType(); |
| 2425 | |
| 2426 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2427 | |
| 2428 | QualType Result = TL.getType(); |
| 2429 | if (getDerived().AlwaysRebuild() || |
| 2430 | ElementType != T->getElementType() || |
| 2431 | Size != T->getSizeExpr()) { |
| 2432 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2433 | T->getSizeModifier(), |
| 2434 | move(SizeResult), |
| 2435 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2436 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2437 | if (Result.isNull()) |
| 2438 | return QualType(); |
| 2439 | } |
| 2440 | else SizeResult.take(); |
| 2441 | |
| 2442 | // We might have any sort of array type now, but fortunately they |
| 2443 | // all have the same location layout. |
| 2444 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2445 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2446 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2447 | NewTL.setSizeExpr(Size); |
| 2448 | |
| 2449 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2450 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2451 | |
| 2452 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2453 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2454 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2455 | DependentSizedExtVectorTypeLoc TL, |
| 2456 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2457 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2458 | |
| 2459 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2460 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2461 | if (ElementType.isNull()) |
| 2462 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2463 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2464 | // Vector sizes are not potentially evaluated contexts |
| 2465 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2466 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2467 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2468 | if (Size.isInvalid()) |
| 2469 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2470 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2471 | QualType Result = TL.getType(); |
| 2472 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2473 | ElementType != T->getElementType() || |
| 2474 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2475 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2476 | move(Size), |
| 2477 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2478 | if (Result.isNull()) |
| 2479 | return QualType(); |
| 2480 | } |
| 2481 | else Size.take(); |
| 2482 | |
| 2483 | // Result might be dependent or not. |
| 2484 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2485 | DependentSizedExtVectorTypeLoc NewTL |
| 2486 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2487 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2488 | } else { |
| 2489 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2490 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2491 | } |
| 2492 | |
| 2493 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2494 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2495 | |
| 2496 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2498 | VectorTypeLoc TL, |
| 2499 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2500 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2501 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2502 | if (ElementType.isNull()) |
| 2503 | return QualType(); |
| 2504 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2505 | QualType Result = TL.getType(); |
| 2506 | if (getDerived().AlwaysRebuild() || |
| 2507 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2508 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2509 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2510 | if (Result.isNull()) |
| 2511 | return QualType(); |
| 2512 | } |
| 2513 | |
| 2514 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2515 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2516 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2517 | return Result; |
| 2518 | } |
| 2519 | |
| 2520 | template<typename Derived> |
| 2521 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2522 | ExtVectorTypeLoc TL, |
| 2523 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2524 | VectorType *T = TL.getTypePtr(); |
| 2525 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2526 | if (ElementType.isNull()) |
| 2527 | return QualType(); |
| 2528 | |
| 2529 | QualType Result = TL.getType(); |
| 2530 | if (getDerived().AlwaysRebuild() || |
| 2531 | ElementType != T->getElementType()) { |
| 2532 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2533 | T->getNumElements(), |
| 2534 | /*FIXME*/ SourceLocation()); |
| 2535 | if (Result.isNull()) |
| 2536 | return QualType(); |
| 2537 | } |
| 2538 | |
| 2539 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2540 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2541 | |
| 2542 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2544 | |
| 2545 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2546 | ParmVarDecl * |
| 2547 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2548 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2549 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2550 | if (!NewDI) |
| 2551 | return 0; |
| 2552 | |
| 2553 | if (NewDI == OldDI) |
| 2554 | return OldParm; |
| 2555 | else |
| 2556 | return ParmVarDecl::Create(SemaRef.Context, |
| 2557 | OldParm->getDeclContext(), |
| 2558 | OldParm->getLocation(), |
| 2559 | OldParm->getIdentifier(), |
| 2560 | NewDI->getType(), |
| 2561 | NewDI, |
| 2562 | OldParm->getStorageClass(), |
| 2563 | /* DefArg */ NULL); |
| 2564 | } |
| 2565 | |
| 2566 | template<typename Derived> |
| 2567 | bool TreeTransform<Derived>:: |
| 2568 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2569 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2570 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2571 | FunctionProtoType *T = TL.getTypePtr(); |
| 2572 | |
| 2573 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2574 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2575 | |
| 2576 | QualType NewType; |
| 2577 | ParmVarDecl *NewParm; |
| 2578 | |
| 2579 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2580 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2581 | if (!NewParm) |
| 2582 | return true; |
| 2583 | NewType = NewParm->getType(); |
| 2584 | |
| 2585 | // Deal with the possibility that we don't have a parameter |
| 2586 | // declaration for this parameter. |
| 2587 | } else { |
| 2588 | NewParm = 0; |
| 2589 | |
| 2590 | QualType OldType = T->getArgType(i); |
| 2591 | NewType = getDerived().TransformType(OldType); |
| 2592 | if (NewType.isNull()) |
| 2593 | return true; |
| 2594 | } |
| 2595 | |
| 2596 | PTypes.push_back(NewType); |
| 2597 | PVars.push_back(NewParm); |
| 2598 | } |
| 2599 | |
| 2600 | return false; |
| 2601 | } |
| 2602 | |
| 2603 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2605 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2606 | FunctionProtoTypeLoc TL, |
| 2607 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2608 | FunctionProtoType *T = TL.getTypePtr(); |
| 2609 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2610 | if (ResultType.isNull()) |
| 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 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2614 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2615 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2616 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2617 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2618 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2619 | QualType Result = TL.getType(); |
| 2620 | if (getDerived().AlwaysRebuild() || |
| 2621 | ResultType != T->getResultType() || |
| 2622 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2623 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2624 | ParamTypes.data(), |
| 2625 | ParamTypes.size(), |
| 2626 | T->isVariadic(), |
| 2627 | T->getTypeQuals()); |
| 2628 | if (Result.isNull()) |
| 2629 | return QualType(); |
| 2630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2631 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2632 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2633 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2634 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2635 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2636 | NewTL.setArg(i, ParamDecls[i]); |
| 2637 | |
| 2638 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2639 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2640 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2641 | template<typename Derived> |
| 2642 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2643 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2644 | FunctionNoProtoTypeLoc TL, |
| 2645 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2646 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2647 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2648 | if (ResultType.isNull()) |
| 2649 | return QualType(); |
| 2650 | |
| 2651 | QualType Result = TL.getType(); |
| 2652 | if (getDerived().AlwaysRebuild() || |
| 2653 | ResultType != T->getResultType()) |
| 2654 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2655 | |
| 2656 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2657 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2658 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2659 | |
| 2660 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2662 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2663 | template<typename Derived> QualType |
| 2664 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2665 | UnresolvedUsingTypeLoc TL, |
| 2666 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2667 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2668 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2669 | if (!D) |
| 2670 | return QualType(); |
| 2671 | |
| 2672 | QualType Result = TL.getType(); |
| 2673 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2674 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2675 | if (Result.isNull()) |
| 2676 | return QualType(); |
| 2677 | } |
| 2678 | |
| 2679 | // We might get an arbitrary type spec type back. We should at |
| 2680 | // least always get a type spec type, though. |
| 2681 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2682 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2683 | |
| 2684 | return Result; |
| 2685 | } |
| 2686 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2687 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2688 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2689 | TypedefTypeLoc TL, |
| 2690 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2691 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2692 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2693 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2694 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2695 | if (!Typedef) |
| 2696 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2698 | QualType Result = TL.getType(); |
| 2699 | if (getDerived().AlwaysRebuild() || |
| 2700 | Typedef != T->getDecl()) { |
| 2701 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2702 | if (Result.isNull()) |
| 2703 | return QualType(); |
| 2704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2705 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2706 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2707 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2708 | |
| 2709 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2712 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2713 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2714 | TypeOfExprTypeLoc TL, |
| 2715 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2716 | // typeof expressions are not potentially evaluated contexts |
| 2717 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2718 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2719 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2720 | if (E.isInvalid()) |
| 2721 | return QualType(); |
| 2722 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2723 | QualType Result = TL.getType(); |
| 2724 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2725 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2727 | if (Result.isNull()) |
| 2728 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2729 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2730 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2732 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2733 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2734 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2735 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2736 | |
| 2737 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2738 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2739 | |
| 2740 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2741 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2742 | TypeOfTypeLoc TL, |
| 2743 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2744 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2745 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2746 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2749 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2750 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2751 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2752 | if (Result.isNull()) |
| 2753 | return QualType(); |
| 2754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2755 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2756 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2757 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2758 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2759 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2760 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | |
| 2762 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2763 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2764 | |
| 2765 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2766 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2767 | DecltypeTypeLoc TL, |
| 2768 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2769 | DecltypeType *T = TL.getTypePtr(); |
| 2770 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2771 | // decltype expressions are not potentially evaluated contexts |
| 2772 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2773 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2774 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2775 | if (E.isInvalid()) |
| 2776 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2777 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2778 | QualType Result = TL.getType(); |
| 2779 | if (getDerived().AlwaysRebuild() || |
| 2780 | E.get() != T->getUnderlyingExpr()) { |
| 2781 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2782 | if (Result.isNull()) |
| 2783 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2784 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2785 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2786 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2787 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2788 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2789 | |
| 2790 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2794 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2795 | RecordTypeLoc TL, |
| 2796 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2798 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2799 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2800 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2801 | if (!Record) |
| 2802 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2803 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2804 | QualType Result = TL.getType(); |
| 2805 | if (getDerived().AlwaysRebuild() || |
| 2806 | Record != T->getDecl()) { |
| 2807 | Result = getDerived().RebuildRecordType(Record); |
| 2808 | if (Result.isNull()) |
| 2809 | return QualType(); |
| 2810 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2812 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2813 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2814 | |
| 2815 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2816 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2817 | |
| 2818 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2819 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2820 | EnumTypeLoc TL, |
| 2821 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2822 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2823 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2824 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2825 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2826 | if (!Enum) |
| 2827 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2828 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | QualType Result = TL.getType(); |
| 2830 | if (getDerived().AlwaysRebuild() || |
| 2831 | Enum != T->getDecl()) { |
| 2832 | Result = getDerived().RebuildEnumType(Enum); |
| 2833 | if (Result.isNull()) |
| 2834 | return QualType(); |
| 2835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2836 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2838 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2839 | |
| 2840 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2841 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2842 | |
| 2843 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2844 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2845 | ElaboratedTypeLoc TL, |
| 2846 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2847 | ElaboratedType *T = TL.getTypePtr(); |
| 2848 | |
| 2849 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2850 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2851 | if (Underlying.isNull()) |
| 2852 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2853 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2854 | QualType Result = TL.getType(); |
| 2855 | if (getDerived().AlwaysRebuild() || |
| 2856 | Underlying != T->getUnderlyingType()) { |
| 2857 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2858 | if (Result.isNull()) |
| 2859 | return QualType(); |
| 2860 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2861 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2862 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2863 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2864 | |
| 2865 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2867 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2868 | template<typename Derived> |
| 2869 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 2870 | TypeLocBuilder &TLB, |
| 2871 | InjectedClassNameTypeLoc TL, |
| 2872 | QualType ObjectType) { |
| 2873 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 2874 | TL.getTypePtr()->getDecl()); |
| 2875 | if (!D) return QualType(); |
| 2876 | |
| 2877 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 2878 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 2879 | return T; |
| 2880 | } |
| 2881 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2882 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2883 | template<typename Derived> |
| 2884 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2885 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2886 | TemplateTypeParmTypeLoc TL, |
| 2887 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2888 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2891 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2892 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2893 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2894 | SubstTemplateTypeParmTypeLoc TL, |
| 2895 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2896 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2900 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2901 | const TemplateSpecializationType *TST, |
| 2902 | QualType ObjectType) { |
| 2903 | // FIXME: this entire method is a temporary workaround; callers |
| 2904 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2905 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2906 | // Fake up a TemplateSpecializationTypeLoc. |
| 2907 | TypeLocBuilder TLB; |
| 2908 | TemplateSpecializationTypeLoc TL |
| 2909 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2910 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2911 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2912 | |
| 2913 | TL.setTemplateNameLoc(BaseLoc); |
| 2914 | TL.setLAngleLoc(BaseLoc); |
| 2915 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2916 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2917 | const TemplateArgument &TA = TST->getArg(i); |
| 2918 | TemplateArgumentLoc TAL; |
| 2919 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2920 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2921 | } |
| 2922 | |
| 2923 | TypeLocBuilder IgnoredTLB; |
| 2924 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2928 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2929 | TypeLocBuilder &TLB, |
| 2930 | TemplateSpecializationTypeLoc TL, |
| 2931 | QualType ObjectType) { |
| 2932 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2933 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2935 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2936 | if (Template.isNull()) |
| 2937 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2938 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2939 | TemplateArgumentListInfo NewTemplateArgs; |
| 2940 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2941 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2942 | |
| 2943 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2944 | TemplateArgumentLoc Loc; |
| 2945 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2946 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2947 | NewTemplateArgs.addArgument(Loc); |
| 2948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2949 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2950 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2951 | |
| 2952 | QualType Result = |
| 2953 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2954 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2955 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2956 | |
| 2957 | if (!Result.isNull()) { |
| 2958 | TemplateSpecializationTypeLoc NewTL |
| 2959 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2960 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2961 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2962 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2963 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2964 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2965 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2966 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2967 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
| 2970 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2971 | QualType |
| 2972 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2973 | QualifiedNameTypeLoc TL, |
| 2974 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2975 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2976 | NestedNameSpecifier *NNS |
| 2977 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2978 | SourceRange(), |
| 2979 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2980 | if (!NNS) |
| 2981 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2982 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2983 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2984 | if (Named.isNull()) |
| 2985 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2987 | QualType Result = TL.getType(); |
| 2988 | if (getDerived().AlwaysRebuild() || |
| 2989 | NNS != T->getQualifier() || |
| 2990 | Named != T->getNamedType()) { |
| 2991 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2992 | if (Result.isNull()) |
| 2993 | return QualType(); |
| 2994 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2995 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2996 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2997 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2998 | |
| 2999 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3000 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3001 | |
| 3002 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3003 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3004 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3005 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3006 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3007 | |
| 3008 | /* FIXME: preserve source information better than this */ |
| 3009 | SourceRange SR(TL.getNameLoc()); |
| 3010 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3011 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3012 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3013 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3014 | if (!NNS) |
| 3015 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3016 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3017 | QualType Result; |
| 3018 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3019 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3020 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3021 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3022 | if (NewTemplateId.isNull()) |
| 3023 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3025 | if (!getDerived().AlwaysRebuild() && |
| 3026 | NNS == T->getQualifier() && |
| 3027 | NewTemplateId == QualType(TemplateId, 0)) |
| 3028 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3029 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3030 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3031 | NewTemplateId); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3032 | } else { |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3033 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3034 | T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3035 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3036 | if (Result.isNull()) |
| 3037 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3038 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3039 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3040 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3041 | |
| 3042 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3045 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3046 | QualType |
| 3047 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3048 | ObjCInterfaceTypeLoc TL, |
| 3049 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3050 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 3051 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
| 3054 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3055 | QualType |
| 3056 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3057 | ObjCObjectPointerTypeLoc TL, |
| 3058 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3059 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3060 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3061 | } |
| 3062 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3063 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3064 | // Statement transformation |
| 3065 | //===----------------------------------------------------------------------===// |
| 3066 | template<typename Derived> |
| 3067 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3068 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3069 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | template<typename Derived> |
| 3073 | Sema::OwningStmtResult |
| 3074 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3075 | return getDerived().TransformCompoundStmt(S, false); |
| 3076 | } |
| 3077 | |
| 3078 | template<typename Derived> |
| 3079 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3080 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3081 | bool IsStmtExpr) { |
| 3082 | bool SubStmtChanged = false; |
| 3083 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3084 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3085 | B != BEnd; ++B) { |
| 3086 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3087 | if (Result.isInvalid()) |
| 3088 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3089 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3090 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3091 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3092 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3094 | if (!getDerived().AlwaysRebuild() && |
| 3095 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3096 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3097 | |
| 3098 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3099 | move_arg(Statements), |
| 3100 | S->getRBracLoc(), |
| 3101 | IsStmtExpr); |
| 3102 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3104 | template<typename Derived> |
| 3105 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3106 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3107 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3108 | { |
| 3109 | // The case value expressions are not potentially evaluated. |
| 3110 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3112 | // Transform the left-hand case value. |
| 3113 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3114 | if (LHS.isInvalid()) |
| 3115 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3116 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3117 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3118 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3119 | if (RHS.isInvalid()) |
| 3120 | return SemaRef.StmtError(); |
| 3121 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3122 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3123 | // Build the case statement. |
| 3124 | // Case statements are always rebuilt so that they will attached to their |
| 3125 | // transformed switch statement. |
| 3126 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3127 | move(LHS), |
| 3128 | S->getEllipsisLoc(), |
| 3129 | move(RHS), |
| 3130 | S->getColonLoc()); |
| 3131 | if (Case.isInvalid()) |
| 3132 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3134 | // Transform the statement following the case |
| 3135 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3136 | if (SubStmt.isInvalid()) |
| 3137 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3138 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3139 | // Attach the body to the case statement |
| 3140 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3141 | } |
| 3142 | |
| 3143 | template<typename Derived> |
| 3144 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3145 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3146 | // Transform the statement following the default case |
| 3147 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3148 | if (SubStmt.isInvalid()) |
| 3149 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3150 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3151 | // Default statements are always rebuilt |
| 3152 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3153 | move(SubStmt)); |
| 3154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3155 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3156 | template<typename Derived> |
| 3157 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3160 | if (SubStmt.isInvalid()) |
| 3161 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | // FIXME: Pass the real colon location in. |
| 3164 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3165 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3166 | move(SubStmt)); |
| 3167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3169 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3170 | Sema::OwningStmtResult |
| 3171 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3172 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3173 | OwningExprResult Cond(SemaRef); |
| 3174 | VarDecl *ConditionVar = 0; |
| 3175 | if (S->getConditionVariable()) { |
| 3176 | ConditionVar |
| 3177 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3178 | getDerived().TransformDefinition( |
| 3179 | S->getConditionVariable()->getLocation(), |
| 3180 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3181 | if (!ConditionVar) |
| 3182 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3183 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3184 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3185 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3186 | if (Cond.isInvalid()) |
| 3187 | return SemaRef.StmtError(); |
| 3188 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3189 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3190 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3192 | // Transform the "then" branch. |
| 3193 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3194 | if (Then.isInvalid()) |
| 3195 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3197 | // Transform the "else" branch. |
| 3198 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3199 | if (Else.isInvalid()) |
| 3200 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3202 | if (!getDerived().AlwaysRebuild() && |
| 3203 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3204 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3205 | Then.get() == S->getThen() && |
| 3206 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3207 | return SemaRef.Owned(S->Retain()); |
| 3208 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3209 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3210 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3211 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | template<typename Derived> |
| 3215 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3216 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3217 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3218 | OwningExprResult Cond(SemaRef); |
| 3219 | VarDecl *ConditionVar = 0; |
| 3220 | if (S->getConditionVariable()) { |
| 3221 | ConditionVar |
| 3222 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3223 | getDerived().TransformDefinition( |
| 3224 | S->getConditionVariable()->getLocation(), |
| 3225 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3226 | if (!ConditionVar) |
| 3227 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3228 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3229 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3230 | |
| 3231 | if (Cond.isInvalid()) |
| 3232 | return SemaRef.StmtError(); |
| 3233 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3235 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3236 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3237 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3238 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3239 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3240 | if (Switch.isInvalid()) |
| 3241 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3242 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3243 | // Transform the body of the switch statement. |
| 3244 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3245 | if (Body.isInvalid()) |
| 3246 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3247 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3248 | // Complete the switch statement. |
| 3249 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3250 | move(Body)); |
| 3251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3253 | template<typename Derived> |
| 3254 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3257 | OwningExprResult Cond(SemaRef); |
| 3258 | VarDecl *ConditionVar = 0; |
| 3259 | if (S->getConditionVariable()) { |
| 3260 | ConditionVar |
| 3261 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3262 | getDerived().TransformDefinition( |
| 3263 | S->getConditionVariable()->getLocation(), |
| 3264 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3265 | if (!ConditionVar) |
| 3266 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3267 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3268 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3269 | |
| 3270 | if (Cond.isInvalid()) |
| 3271 | return SemaRef.StmtError(); |
| 3272 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3274 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | // Transform the body |
| 3277 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3278 | if (Body.isInvalid()) |
| 3279 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3281 | if (!getDerived().AlwaysRebuild() && |
| 3282 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3283 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | return SemaRef.Owned(S->Retain()); |
| 3286 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3287 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3288 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3289 | } |
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 | template<typename Derived> |
| 3292 | Sema::OwningStmtResult |
| 3293 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3294 | // Transform the condition |
| 3295 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3296 | if (Cond.isInvalid()) |
| 3297 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3298 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3299 | // Transform the body |
| 3300 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3301 | if (Body.isInvalid()) |
| 3302 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | if (!getDerived().AlwaysRebuild() && |
| 3305 | Cond.get() == S->getCond() && |
| 3306 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | return SemaRef.Owned(S->Retain()); |
| 3308 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3310 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3311 | S->getRParenLoc()); |
| 3312 | } |
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 | template<typename Derived> |
| 3315 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | // Transform the initialization statement |
| 3318 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3319 | if (Init.isInvalid()) |
| 3320 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3322 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3323 | OwningExprResult Cond(SemaRef); |
| 3324 | VarDecl *ConditionVar = 0; |
| 3325 | if (S->getConditionVariable()) { |
| 3326 | ConditionVar |
| 3327 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3328 | getDerived().TransformDefinition( |
| 3329 | S->getConditionVariable()->getLocation(), |
| 3330 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3331 | if (!ConditionVar) |
| 3332 | return SemaRef.StmtError(); |
| 3333 | } else { |
| 3334 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3335 | |
| 3336 | if (Cond.isInvalid()) |
| 3337 | return SemaRef.StmtError(); |
| 3338 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3339 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3340 | // Transform the increment |
| 3341 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3342 | if (Inc.isInvalid()) |
| 3343 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3345 | // Transform the body |
| 3346 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3347 | if (Body.isInvalid()) |
| 3348 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3349 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | if (!getDerived().AlwaysRebuild() && |
| 3351 | Init.get() == S->getInit() && |
| 3352 | Cond.get() == S->getCond() && |
| 3353 | Inc.get() == S->getInc() && |
| 3354 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | return SemaRef.Owned(S->Retain()); |
| 3356 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3358 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3359 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3360 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3361 | S->getRParenLoc(), move(Body)); |
| 3362 | } |
| 3363 | |
| 3364 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | Sema::OwningStmtResult |
| 3366 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3367 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3368 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3369 | S->getLabel()); |
| 3370 | } |
| 3371 | |
| 3372 | template<typename Derived> |
| 3373 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3375 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3376 | if (Target.isInvalid()) |
| 3377 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3378 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3379 | if (!getDerived().AlwaysRebuild() && |
| 3380 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3382 | |
| 3383 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3384 | move(Target)); |
| 3385 | } |
| 3386 | |
| 3387 | template<typename Derived> |
| 3388 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3389 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3390 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3392 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3393 | template<typename Derived> |
| 3394 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3396 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3398 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3399 | template<typename Derived> |
| 3400 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3401 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3402 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3403 | if (Result.isInvalid()) |
| 3404 | return SemaRef.StmtError(); |
| 3405 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3406 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3407 | // to tell whether the return type of the function has changed. |
| 3408 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3409 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3411 | template<typename Derived> |
| 3412 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3413 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | bool DeclChanged = false; |
| 3415 | llvm::SmallVector<Decl *, 4> Decls; |
| 3416 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3417 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3418 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3419 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3420 | if (!Transformed) |
| 3421 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3423 | if (Transformed != *D) |
| 3424 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3426 | Decls.push_back(Transformed); |
| 3427 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3430 | return SemaRef.Owned(S->Retain()); |
| 3431 | |
| 3432 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | S->getStartLoc(), S->getEndLoc()); |
| 3434 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3435 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3436 | template<typename Derived> |
| 3437 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3439 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3440 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | template<typename Derived> |
| 3444 | Sema::OwningStmtResult |
| 3445 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3446 | |
| 3447 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3448 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3449 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3450 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3451 | OwningExprResult AsmString(SemaRef); |
| 3452 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3453 | |
| 3454 | bool ExprsChanged = false; |
| 3455 | |
| 3456 | // Go through the outputs. |
| 3457 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3458 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3459 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3460 | // No need to transform the constraint literal. |
| 3461 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3462 | |
| 3463 | // Transform the output expr. |
| 3464 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3465 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3466 | if (Result.isInvalid()) |
| 3467 | return SemaRef.StmtError(); |
| 3468 | |
| 3469 | ExprsChanged |= Result.get() != OutputExpr; |
| 3470 | |
| 3471 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3472 | } |
| 3473 | |
| 3474 | // Go through the inputs. |
| 3475 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3476 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3477 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3478 | // No need to transform the constraint literal. |
| 3479 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3480 | |
| 3481 | // Transform the input expr. |
| 3482 | Expr *InputExpr = S->getInputExpr(I); |
| 3483 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3484 | if (Result.isInvalid()) |
| 3485 | return SemaRef.StmtError(); |
| 3486 | |
| 3487 | ExprsChanged |= Result.get() != InputExpr; |
| 3488 | |
| 3489 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3490 | } |
| 3491 | |
| 3492 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3493 | return SemaRef.Owned(S->Retain()); |
| 3494 | |
| 3495 | // Go through the clobbers. |
| 3496 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3497 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3498 | |
| 3499 | // No need to transform the asm string literal. |
| 3500 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3501 | |
| 3502 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3503 | S->isSimple(), |
| 3504 | S->isVolatile(), |
| 3505 | S->getNumOutputs(), |
| 3506 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3507 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3508 | move_arg(Constraints), |
| 3509 | move_arg(Exprs), |
| 3510 | move(AsmString), |
| 3511 | move_arg(Clobbers), |
| 3512 | S->getRParenLoc(), |
| 3513 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | |
| 3517 | template<typename Derived> |
| 3518 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *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 @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3522 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *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 @catch statement"); |
| 3530 | return SemaRef.Owned(S->Retain()); |
| 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>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *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 @finally 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 |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3544 | // FIXME: Implement this |
| 3545 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3546 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3549 | template<typename Derived> |
| 3550 | Sema::OwningStmtResult |
| 3551 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3553 | // FIXME: Implement this |
| 3554 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | template<typename Derived> |
| 3559 | Sema::OwningStmtResult |
| 3560 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3562 | // FIXME: Implement this |
| 3563 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | |
| 3568 | template<typename Derived> |
| 3569 | Sema::OwningStmtResult |
| 3570 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3571 | // Transform the exception declaration, if any. |
| 3572 | VarDecl *Var = 0; |
| 3573 | if (S->getExceptionDecl()) { |
| 3574 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3575 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3576 | ExceptionDecl->getDeclName()); |
| 3577 | |
| 3578 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3579 | if (T.isNull()) |
| 3580 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3581 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3582 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3583 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3584 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3585 | ExceptionDecl->getIdentifier(), |
| 3586 | ExceptionDecl->getLocation(), |
| 3587 | /*FIXME: Inaccurate*/ |
| 3588 | SourceRange(ExceptionDecl->getLocation())); |
| 3589 | if (!Var || Var->isInvalidDecl()) { |
| 3590 | if (Var) |
| 3591 | Var->Destroy(SemaRef.Context); |
| 3592 | return SemaRef.StmtError(); |
| 3593 | } |
| 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 | // Transform the actual exception handler. |
| 3597 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3598 | if (Handler.isInvalid()) { |
| 3599 | if (Var) |
| 3600 | Var->Destroy(SemaRef.Context); |
| 3601 | return SemaRef.StmtError(); |
| 3602 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3603 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3604 | if (!getDerived().AlwaysRebuild() && |
| 3605 | !Var && |
| 3606 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3607 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3608 | |
| 3609 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3610 | Var, |
| 3611 | move(Handler)); |
| 3612 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3613 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3614 | template<typename Derived> |
| 3615 | Sema::OwningStmtResult |
| 3616 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3617 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3619 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3620 | if (TryBlock.isInvalid()) |
| 3621 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3623 | // Transform the handlers. |
| 3624 | bool HandlerChanged = false; |
| 3625 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3626 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3628 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3629 | if (Handler.isInvalid()) |
| 3630 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3632 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3633 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3636 | if (!getDerived().AlwaysRebuild() && |
| 3637 | TryBlock.get() == S->getTryBlock() && |
| 3638 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3640 | |
| 3641 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3642 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3643 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3644 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3645 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | // Expression transformation |
| 3647 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3648 | template<typename Derived> |
| 3649 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3650 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
| 3654 | template<typename Derived> |
| 3655 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3656 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3657 | NestedNameSpecifier *Qualifier = 0; |
| 3658 | if (E->getQualifier()) { |
| 3659 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3660 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3661 | if (!Qualifier) |
| 3662 | return SemaRef.ExprError(); |
| 3663 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3664 | |
| 3665 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3666 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3667 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3668 | if (!ND) |
| 3669 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3671 | if (!getDerived().AlwaysRebuild() && |
| 3672 | Qualifier == E->getQualifier() && |
| 3673 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3674 | !E->hasExplicitTemplateArgumentList()) { |
| 3675 | |
| 3676 | // Mark it referenced in the new context regardless. |
| 3677 | // FIXME: this is a bit instantiation-specific. |
| 3678 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3679 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3681 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3682 | |
| 3683 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3684 | if (E->hasExplicitTemplateArgumentList()) { |
| 3685 | TemplateArgs = &TransArgs; |
| 3686 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3687 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3688 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3689 | TemplateArgumentLoc Loc; |
| 3690 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3691 | return SemaRef.ExprError(); |
| 3692 | TransArgs.addArgument(Loc); |
| 3693 | } |
| 3694 | } |
| 3695 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3696 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3697 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3698 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3700 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3701 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3702 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3703 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3706 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3707 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3708 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3712 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3714 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3716 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3718 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3719 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3720 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3723 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3724 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3726 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | return SemaRef.Owned(E->Retain()); |
| 3728 | } |
| 3729 | |
| 3730 | template<typename Derived> |
| 3731 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3732 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3733 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3734 | if (SubExpr.isInvalid()) |
| 3735 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3737 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | return SemaRef.Owned(E->Retain()); |
| 3739 | |
| 3740 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3741 | E->getRParen()); |
| 3742 | } |
| 3743 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3744 | template<typename Derived> |
| 3745 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3746 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3747 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | if (SubExpr.isInvalid()) |
| 3749 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | return SemaRef.Owned(E->Retain()); |
| 3753 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3755 | E->getOpcode(), |
| 3756 | move(SubExpr)); |
| 3757 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3759 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3761 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3762 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3763 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3764 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3765 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3766 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3767 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3769 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3770 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3771 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3772 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3774 | E->getSourceRange()); |
| 3775 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3776 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3777 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3779 | // C++0x [expr.sizeof]p1: |
| 3780 | // The operand is either an expression, which is an unevaluated operand |
| 3781 | // [...] |
| 3782 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
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 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3785 | if (SubExpr.isInvalid()) |
| 3786 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3788 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3789 | return SemaRef.Owned(E->Retain()); |
| 3790 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3793 | E->isSizeOf(), |
| 3794 | E->getSourceRange()); |
| 3795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3797 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3799 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3800 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3801 | if (LHS.isInvalid()) |
| 3802 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3803 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3804 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3805 | if (RHS.isInvalid()) |
| 3806 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3807 | |
| 3808 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3809 | if (!getDerived().AlwaysRebuild() && |
| 3810 | LHS.get() == E->getLHS() && |
| 3811 | RHS.get() == E->getRHS()) |
| 3812 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3814 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3815 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3816 | move(RHS), |
| 3817 | E->getRBracketLoc()); |
| 3818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
| 3820 | template<typename Derived> |
| 3821 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3822 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3823 | // Transform the callee. |
| 3824 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3825 | if (Callee.isInvalid()) |
| 3826 | return SemaRef.ExprError(); |
| 3827 | |
| 3828 | // Transform arguments. |
| 3829 | bool ArgChanged = false; |
| 3830 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3831 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3832 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3833 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3834 | if (Arg.isInvalid()) |
| 3835 | return SemaRef.ExprError(); |
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 | // FIXME: Wrong source location information for the ','. |
| 3838 | FakeCommaLocs.push_back( |
| 3839 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | |
| 3841 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | Args.push_back(Arg.takeAs<Expr>()); |
| 3843 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | if (!getDerived().AlwaysRebuild() && |
| 3846 | Callee.get() == E->getCallee() && |
| 3847 | !ArgChanged) |
| 3848 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3850 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3851 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3852 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3853 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3854 | move_arg(Args), |
| 3855 | FakeCommaLocs.data(), |
| 3856 | E->getRParenLoc()); |
| 3857 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
| 3859 | template<typename Derived> |
| 3860 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3861 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3862 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3863 | if (Base.isInvalid()) |
| 3864 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3865 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3866 | NestedNameSpecifier *Qualifier = 0; |
| 3867 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3868 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3869 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3870 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3871 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3872 | return SemaRef.ExprError(); |
| 3873 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3875 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3876 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 3877 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3878 | if (!Member) |
| 3879 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3880 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 3881 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 3882 | if (FoundDecl == E->getMemberDecl()) { |
| 3883 | FoundDecl = Member; |
| 3884 | } else { |
| 3885 | FoundDecl = cast_or_null<NamedDecl>( |
| 3886 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 3887 | if (!FoundDecl) |
| 3888 | return SemaRef.ExprError(); |
| 3889 | } |
| 3890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3891 | if (!getDerived().AlwaysRebuild() && |
| 3892 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3893 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3894 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 3895 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3896 | !E->hasExplicitTemplateArgumentList()) { |
| 3897 | |
| 3898 | // Mark it referenced in the new context regardless. |
| 3899 | // FIXME: this is a bit instantiation-specific. |
| 3900 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3902 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3903 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3904 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3905 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3906 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3907 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3908 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3909 | TemplateArgumentLoc Loc; |
| 3910 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3911 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3912 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3913 | } |
| 3914 | } |
| 3915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | // FIXME: Bogus source location for the operator |
| 3917 | SourceLocation FakeOperatorLoc |
| 3918 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3919 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3920 | // FIXME: to do this check properly, we will need to preserve the |
| 3921 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3922 | // base (and therefore couldn't do the check) and a |
| 3923 | // nested-name-qualifier (and therefore could do the lookup). |
| 3924 | NamedDecl *FirstQualifierInScope = 0; |
| 3925 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3926 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3927 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3928 | Qualifier, |
| 3929 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3931 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 3932 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3933 | (E->hasExplicitTemplateArgumentList() |
| 3934 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3935 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3938 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3939 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3940 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3941 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3942 | if (LHS.isInvalid()) |
| 3943 | return SemaRef.ExprError(); |
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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3946 | if (RHS.isInvalid()) |
| 3947 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3948 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3949 | if (!getDerived().AlwaysRebuild() && |
| 3950 | LHS.get() == E->getLHS() && |
| 3951 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | return SemaRef.Owned(E->Retain()); |
| 3953 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3954 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3955 | move(LHS), move(RHS)); |
| 3956 | } |
| 3957 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3958 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | Sema::OwningExprResult |
| 3960 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3961 | CompoundAssignOperator *E) { |
| 3962 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3964 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3965 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3967 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3968 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3969 | if (Cond.isInvalid()) |
| 3970 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3971 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3972 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3973 | if (LHS.isInvalid()) |
| 3974 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3975 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3976 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3977 | if (RHS.isInvalid()) |
| 3978 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | if (!getDerived().AlwaysRebuild() && |
| 3981 | Cond.get() == E->getCond() && |
| 3982 | LHS.get() == E->getLHS() && |
| 3983 | RHS.get() == E->getRHS()) |
| 3984 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3985 | |
| 3986 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3987 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3989 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3990 | move(RHS)); |
| 3991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | |
| 3993 | template<typename Derived> |
| 3994 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3995 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3996 | // Implicit casts are eliminated during transformation, since they |
| 3997 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3998 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
| 4002 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4003 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4004 | TypeSourceInfo *OldT; |
| 4005 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | { |
| 4007 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4008 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4010 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4011 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4012 | OldT = E->getTypeInfoAsWritten(); |
| 4013 | NewT = getDerived().TransformType(OldT); |
| 4014 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4015 | return SemaRef.ExprError(); |
| 4016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4018 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4019 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4020 | if (SubExpr.isInvalid()) |
| 4021 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4023 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4024 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4025 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4026 | return SemaRef.Owned(E->Retain()); |
| 4027 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4028 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4029 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4030 | E->getRParenLoc(), |
| 4031 | move(SubExpr)); |
| 4032 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4033 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4034 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4035 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4036 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4037 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4038 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4039 | if (!NewT) |
| 4040 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4042 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4043 | if (Init.isInvalid()) |
| 4044 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4047 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4050 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4051 | // Note: the expression type doesn't necessarily match the |
| 4052 | // type-as-written, but that's okay, because it should always be |
| 4053 | // derivable from the initializer. |
| 4054 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4055 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4056 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4057 | move(Init)); |
| 4058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4060 | template<typename Derived> |
| 4061 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4062 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4063 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4064 | if (Base.isInvalid()) |
| 4065 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4067 | if (!getDerived().AlwaysRebuild() && |
| 4068 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | return SemaRef.Owned(E->Retain()); |
| 4070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4071 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4072 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4073 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4074 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4075 | E->getAccessorLoc(), |
| 4076 | E->getAccessor()); |
| 4077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4078 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4079 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4081 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4082 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4085 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4086 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4087 | if (Init.isInvalid()) |
| 4088 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4090 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4091 | Inits.push_back(Init.takeAs<Expr>()); |
| 4092 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4094 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4095 | return SemaRef.Owned(E->Retain()); |
| 4096 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4098 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4099 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4101 | template<typename Derived> |
| 4102 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4103 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4106 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4108 | if (Init.isInvalid()) |
| 4109 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4111 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4112 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4113 | bool ExprChanged = false; |
| 4114 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4115 | DEnd = E->designators_end(); |
| 4116 | D != DEnd; ++D) { |
| 4117 | if (D->isFieldDesignator()) { |
| 4118 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4119 | D->getDotLoc(), |
| 4120 | D->getFieldLoc())); |
| 4121 | continue; |
| 4122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | if (D->isArrayDesignator()) { |
| 4125 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4126 | if (Index.isInvalid()) |
| 4127 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4128 | |
| 4129 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | D->getLBracketLoc())); |
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 || Init.get() != E->getArrayIndex(*D); |
| 4133 | ArrayExprs.push_back(Index.release()); |
| 4134 | continue; |
| 4135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4137 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4139 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4140 | if (Start.isInvalid()) |
| 4141 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4142 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4143 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4144 | if (End.isInvalid()) |
| 4145 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | |
| 4147 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4148 | End.get(), |
| 4149 | D->getLBracketLoc(), |
| 4150 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4151 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4152 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4153 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | ArrayExprs.push_back(Start.release()); |
| 4156 | ArrayExprs.push_back(End.release()); |
| 4157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | if (!getDerived().AlwaysRebuild() && |
| 4160 | Init.get() == E->getInit() && |
| 4161 | !ExprChanged) |
| 4162 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4163 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4165 | E->getEqualOrColonLoc(), |
| 4166 | E->usesGNUSyntax(), move(Init)); |
| 4167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4169 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4172 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4173 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4174 | |
| 4175 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4176 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4177 | QualType T = getDerived().TransformType(E->getType()); |
| 4178 | if (T.isNull()) |
| 4179 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4180 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | if (!getDerived().AlwaysRebuild() && |
| 4182 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | return SemaRef.Owned(E->Retain()); |
| 4184 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4190 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4191 | // FIXME: Do we want the type as written? |
| 4192 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | { |
| 4195 | // FIXME: Source location isn't quite accurate. |
| 4196 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4197 | T = getDerived().TransformType(E->getType()); |
| 4198 | if (T.isNull()) |
| 4199 | return SemaRef.ExprError(); |
| 4200 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4203 | if (SubExpr.isInvalid()) |
| 4204 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4206 | if (!getDerived().AlwaysRebuild() && |
| 4207 | T == E->getType() && |
| 4208 | SubExpr.get() == E->getSubExpr()) |
| 4209 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4212 | T, E->getRParenLoc()); |
| 4213 | } |
| 4214 | |
| 4215 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4217 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | bool ArgumentChanged = false; |
| 4219 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4220 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4221 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4222 | if (Init.isInvalid()) |
| 4223 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4224 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4225 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4226 | Inits.push_back(Init.takeAs<Expr>()); |
| 4227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4230 | move_arg(Inits), |
| 4231 | E->getRParenLoc()); |
| 4232 | } |
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 | /// \brief Transform an address-of-label expression. |
| 4235 | /// |
| 4236 | /// By default, the transformation of an address-of-label expression always |
| 4237 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4238 | /// the corresponding label statement by semantic analysis. |
| 4239 | template<typename Derived> |
| 4240 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4241 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4242 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4243 | E->getLabel()); |
| 4244 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4245 | |
| 4246 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4247 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4248 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4249 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4250 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4251 | if (SubStmt.isInvalid()) |
| 4252 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | if (!getDerived().AlwaysRebuild() && |
| 4255 | SubStmt.get() == E->getSubStmt()) |
| 4256 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | |
| 4258 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4259 | move(SubStmt), |
| 4260 | E->getRParenLoc()); |
| 4261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | template<typename Derived> |
| 4264 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4265 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4266 | QualType T1, T2; |
| 4267 | { |
| 4268 | // FIXME: Source location isn't quite accurate. |
| 4269 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4271 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4272 | if (T1.isNull()) |
| 4273 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4274 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4275 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4276 | if (T2.isNull()) |
| 4277 | return SemaRef.ExprError(); |
| 4278 | } |
| 4279 | |
| 4280 | if (!getDerived().AlwaysRebuild() && |
| 4281 | T1 == E->getArgType1() && |
| 4282 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | return SemaRef.Owned(E->Retain()); |
| 4284 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4286 | T1, T2, E->getRParenLoc()); |
| 4287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | template<typename Derived> |
| 4290 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4291 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4292 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4293 | if (Cond.isInvalid()) |
| 4294 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4297 | if (LHS.isInvalid()) |
| 4298 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4299 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4300 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4301 | if (RHS.isInvalid()) |
| 4302 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | if (!getDerived().AlwaysRebuild() && |
| 4305 | Cond.get() == E->getCond() && |
| 4306 | LHS.get() == E->getLHS() && |
| 4307 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4308 | return SemaRef.Owned(E->Retain()); |
| 4309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4311 | move(Cond), move(LHS), move(RHS), |
| 4312 | E->getRParenLoc()); |
| 4313 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4315 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4317 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | template<typename Derived> |
| 4322 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4323 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4324 | switch (E->getOperator()) { |
| 4325 | case OO_New: |
| 4326 | case OO_Delete: |
| 4327 | case OO_Array_New: |
| 4328 | case OO_Array_Delete: |
| 4329 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4330 | return SemaRef.ExprError(); |
| 4331 | |
| 4332 | case OO_Call: { |
| 4333 | // This is a call to an object's operator(). |
| 4334 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4335 | |
| 4336 | // Transform the object itself. |
| 4337 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4338 | if (Object.isInvalid()) |
| 4339 | return SemaRef.ExprError(); |
| 4340 | |
| 4341 | // FIXME: Poor location information |
| 4342 | SourceLocation FakeLParenLoc |
| 4343 | = SemaRef.PP.getLocForEndOfToken( |
| 4344 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4345 | |
| 4346 | // Transform the call arguments. |
| 4347 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4348 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4349 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4350 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4351 | break; |
| 4352 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4353 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4354 | if (Arg.isInvalid()) |
| 4355 | return SemaRef.ExprError(); |
| 4356 | |
| 4357 | // FIXME: Poor source location information. |
| 4358 | SourceLocation FakeCommaLoc |
| 4359 | = SemaRef.PP.getLocForEndOfToken( |
| 4360 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4361 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4362 | Args.push_back(Arg.release()); |
| 4363 | } |
| 4364 | |
| 4365 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4366 | move_arg(Args), |
| 4367 | FakeCommaLocs.data(), |
| 4368 | E->getLocEnd()); |
| 4369 | } |
| 4370 | |
| 4371 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4372 | case OO_##Name: |
| 4373 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4374 | #include "clang/Basic/OperatorKinds.def" |
| 4375 | case OO_Subscript: |
| 4376 | // Handled below. |
| 4377 | break; |
| 4378 | |
| 4379 | case OO_Conditional: |
| 4380 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4381 | return SemaRef.ExprError(); |
| 4382 | |
| 4383 | case OO_None: |
| 4384 | case NUM_OVERLOADED_OPERATORS: |
| 4385 | llvm_unreachable("not an overloaded operator?"); |
| 4386 | return SemaRef.ExprError(); |
| 4387 | } |
| 4388 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4390 | if (Callee.isInvalid()) |
| 4391 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4393 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | if (First.isInvalid()) |
| 4395 | return SemaRef.ExprError(); |
| 4396 | |
| 4397 | OwningExprResult Second(SemaRef); |
| 4398 | if (E->getNumArgs() == 2) { |
| 4399 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4400 | if (Second.isInvalid()) |
| 4401 | return SemaRef.ExprError(); |
| 4402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | if (!getDerived().AlwaysRebuild() && |
| 4405 | Callee.get() == E->getCallee() && |
| 4406 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4408 | return SemaRef.Owned(E->Retain()); |
| 4409 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4411 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | move(First), |
| 4414 | move(Second)); |
| 4415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | template<typename Derived> |
| 4418 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4419 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4420 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4425 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4426 | TypeSourceInfo *OldT; |
| 4427 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4428 | { |
| 4429 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4432 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4434 | OldT = E->getTypeInfoAsWritten(); |
| 4435 | NewT = getDerived().TransformType(OldT); |
| 4436 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | return SemaRef.ExprError(); |
| 4438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4440 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4441 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4442 | if (SubExpr.isInvalid()) |
| 4443 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4445 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4446 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4448 | return SemaRef.Owned(E->Retain()); |
| 4449 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4450 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4453 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4454 | SourceLocation FakeRParenLoc |
| 4455 | = SemaRef.PP.getLocForEndOfToken( |
| 4456 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4457 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4460 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4461 | FakeRAngleLoc, |
| 4462 | FakeRAngleLoc, |
| 4463 | move(SubExpr), |
| 4464 | FakeRParenLoc); |
| 4465 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4466 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4467 | template<typename Derived> |
| 4468 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4469 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4470 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4471 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4472 | |
| 4473 | template<typename Derived> |
| 4474 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4475 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4476 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4477 | } |
| 4478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | template<typename Derived> |
| 4480 | Sema::OwningExprResult |
| 4481 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4482 | CXXReinterpretCastExpr *E) { |
| 4483 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4484 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4486 | template<typename Derived> |
| 4487 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4488 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4489 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4490 | } |
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 | template<typename Derived> |
| 4493 | Sema::OwningExprResult |
| 4494 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4495 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4496 | TypeSourceInfo *OldT; |
| 4497 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | { |
| 4499 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4501 | OldT = E->getTypeInfoAsWritten(); |
| 4502 | NewT = getDerived().TransformType(OldT); |
| 4503 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4504 | return SemaRef.ExprError(); |
| 4505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4507 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4508 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | if (SubExpr.isInvalid()) |
| 4510 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4513 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | return SemaRef.Owned(E->Retain()); |
| 4516 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4517 | // FIXME: The end of the type's source range is wrong |
| 4518 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4519 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4520 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4522 | move(SubExpr), |
| 4523 | E->getRParenLoc()); |
| 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 | template<typename Derived> |
| 4527 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4528 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | if (E->isTypeOperand()) { |
| 4530 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4533 | if (T.isNull()) |
| 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 | T == E->getTypeOperand()) |
| 4538 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4541 | /*FIXME:*/E->getLocStart(), |
| 4542 | T, |
| 4543 | E->getLocEnd()); |
| 4544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | // We don't know whether the expression is potentially evaluated until |
| 4547 | // after we perform semantic analysis, so the expression is potentially |
| 4548 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4550 | Action::PotentiallyPotentiallyEvaluated); |
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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4553 | if (SubExpr.isInvalid()) |
| 4554 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4555 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4556 | if (!getDerived().AlwaysRebuild() && |
| 4557 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | return SemaRef.Owned(E->Retain()); |
| 4559 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4560 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4561 | /*FIXME:*/E->getLocStart(), |
| 4562 | move(SubExpr), |
| 4563 | E->getLocEnd()); |
| 4564 | } |
| 4565 | |
| 4566 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4567 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4568 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4571 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | template<typename Derived> |
| 4573 | Sema::OwningExprResult |
| 4574 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4575 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | template<typename Derived> |
| 4580 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4581 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | QualType T = getDerived().TransformType(E->getType()); |
| 4585 | if (T.isNull()) |
| 4586 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4588 | if (!getDerived().AlwaysRebuild() && |
| 4589 | T == E->getType()) |
| 4590 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4591 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4592 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4594 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4595 | template<typename Derived> |
| 4596 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4597 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4598 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4599 | if (SubExpr.isInvalid()) |
| 4600 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4602 | if (!getDerived().AlwaysRebuild() && |
| 4603 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4605 | |
| 4606 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4607 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4608 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4609 | template<typename Derived> |
| 4610 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4611 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4613 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4614 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | if (!Param) |
| 4616 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4617 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4618 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | Param == E->getParam()) |
| 4620 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4622 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | template<typename Derived> |
| 4626 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4627 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4628 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4629 | |
| 4630 | QualType T = getDerived().TransformType(E->getType()); |
| 4631 | if (T.isNull()) |
| 4632 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4633 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4634 | if (!getDerived().AlwaysRebuild() && |
| 4635 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4636 | return SemaRef.Owned(E->Retain()); |
| 4637 | |
| 4638 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4640 | T, |
| 4641 | E->getRParenLoc()); |
| 4642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4643 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | template<typename Derived> |
| 4645 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4646 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4647 | // Transform the type that we're allocating |
| 4648 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4649 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4650 | if (AllocType.isNull()) |
| 4651 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4652 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4653 | // Transform the size of the array we're allocating (if any). |
| 4654 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4655 | if (ArraySize.isInvalid()) |
| 4656 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | // Transform the placement arguments (if any). |
| 4659 | bool ArgumentChanged = false; |
| 4660 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4661 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4662 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4663 | if (Arg.isInvalid()) |
| 4664 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4667 | PlacementArgs.push_back(Arg.take()); |
| 4668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4669 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4670 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4671 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4672 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4673 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4674 | if (Arg.isInvalid()) |
| 4675 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4676 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4677 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4678 | ConstructorArgs.push_back(Arg.take()); |
| 4679 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4681 | // Transform constructor, new operator, and delete operator. |
| 4682 | CXXConstructorDecl *Constructor = 0; |
| 4683 | if (E->getConstructor()) { |
| 4684 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4685 | getDerived().TransformDecl(E->getLocStart(), |
| 4686 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4687 | if (!Constructor) |
| 4688 | return SemaRef.ExprError(); |
| 4689 | } |
| 4690 | |
| 4691 | FunctionDecl *OperatorNew = 0; |
| 4692 | if (E->getOperatorNew()) { |
| 4693 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4694 | getDerived().TransformDecl(E->getLocStart(), |
| 4695 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4696 | if (!OperatorNew) |
| 4697 | return SemaRef.ExprError(); |
| 4698 | } |
| 4699 | |
| 4700 | FunctionDecl *OperatorDelete = 0; |
| 4701 | if (E->getOperatorDelete()) { |
| 4702 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4703 | getDerived().TransformDecl(E->getLocStart(), |
| 4704 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4705 | if (!OperatorDelete) |
| 4706 | return SemaRef.ExprError(); |
| 4707 | } |
| 4708 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4709 | if (!getDerived().AlwaysRebuild() && |
| 4710 | AllocType == E->getAllocatedType() && |
| 4711 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4712 | Constructor == E->getConstructor() && |
| 4713 | OperatorNew == E->getOperatorNew() && |
| 4714 | OperatorDelete == E->getOperatorDelete() && |
| 4715 | !ArgumentChanged) { |
| 4716 | // Mark any declarations we need as referenced. |
| 4717 | // FIXME: instantiation-specific. |
| 4718 | if (Constructor) |
| 4719 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4720 | if (OperatorNew) |
| 4721 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4722 | if (OperatorDelete) |
| 4723 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4724 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4725 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4726 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4727 | if (!ArraySize.get()) { |
| 4728 | // If no array size was specified, but the new expression was |
| 4729 | // instantiated with an array type (e.g., "new T" where T is |
| 4730 | // instantiated with "int[4]"), extract the outer bound from the |
| 4731 | // array type as our array size. We do this with constant and |
| 4732 | // dependently-sized array types. |
| 4733 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4734 | if (!ArrayT) { |
| 4735 | // Do nothing |
| 4736 | } else if (const ConstantArrayType *ConsArrayT |
| 4737 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4738 | ArraySize |
| 4739 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4740 | ConsArrayT->getSize(), |
| 4741 | SemaRef.Context.getSizeType(), |
| 4742 | /*FIXME:*/E->getLocStart())); |
| 4743 | AllocType = ConsArrayT->getElementType(); |
| 4744 | } else if (const DependentSizedArrayType *DepArrayT |
| 4745 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4746 | if (DepArrayT->getSizeExpr()) { |
| 4747 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4748 | AllocType = DepArrayT->getElementType(); |
| 4749 | } |
| 4750 | } |
| 4751 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4753 | E->isGlobalNew(), |
| 4754 | /*FIXME:*/E->getLocStart(), |
| 4755 | move_arg(PlacementArgs), |
| 4756 | /*FIXME:*/E->getLocStart(), |
| 4757 | E->isParenTypeId(), |
| 4758 | AllocType, |
| 4759 | /*FIXME:*/E->getLocStart(), |
| 4760 | /*FIXME:*/SourceRange(), |
| 4761 | move(ArraySize), |
| 4762 | /*FIXME:*/E->getLocStart(), |
| 4763 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4765 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4766 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | template<typename Derived> |
| 4768 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4769 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4770 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4771 | if (Operand.isInvalid()) |
| 4772 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4774 | // Transform the delete operator, if known. |
| 4775 | FunctionDecl *OperatorDelete = 0; |
| 4776 | if (E->getOperatorDelete()) { |
| 4777 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4778 | getDerived().TransformDecl(E->getLocStart(), |
| 4779 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4780 | if (!OperatorDelete) |
| 4781 | return SemaRef.ExprError(); |
| 4782 | } |
| 4783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4785 | Operand.get() == E->getArgument() && |
| 4786 | OperatorDelete == E->getOperatorDelete()) { |
| 4787 | // Mark any declarations we need as referenced. |
| 4788 | // FIXME: instantiation-specific. |
| 4789 | if (OperatorDelete) |
| 4790 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4791 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4792 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4793 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4795 | E->isGlobalDelete(), |
| 4796 | E->isArrayForm(), |
| 4797 | move(Operand)); |
| 4798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4799 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | template<typename Derived> |
| 4801 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4802 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4803 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4804 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4805 | if (Base.isInvalid()) |
| 4806 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4807 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4808 | Sema::TypeTy *ObjectTypePtr = 0; |
| 4809 | bool MayBePseudoDestructor = false; |
| 4810 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4811 | E->getOperatorLoc(), |
| 4812 | E->isArrow()? tok::arrow : tok::period, |
| 4813 | ObjectTypePtr, |
| 4814 | MayBePseudoDestructor); |
| 4815 | if (Base.isInvalid()) |
| 4816 | return SemaRef.ExprError(); |
| 4817 | |
| 4818 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4819 | NestedNameSpecifier *Qualifier |
| 4820 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4821 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4822 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4823 | if (E->getQualifier() && !Qualifier) |
| 4824 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4825 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4826 | PseudoDestructorTypeStorage Destroyed; |
| 4827 | if (E->getDestroyedTypeInfo()) { |
| 4828 | TypeSourceInfo *DestroyedTypeInfo |
| 4829 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 4830 | if (!DestroyedTypeInfo) |
| 4831 | return SemaRef.ExprError(); |
| 4832 | Destroyed = DestroyedTypeInfo; |
| 4833 | } else if (ObjectType->isDependentType()) { |
| 4834 | // We aren't likely to be able to resolve the identifier down to a type |
| 4835 | // now anyway, so just retain the identifier. |
| 4836 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 4837 | E->getDestroyedTypeLoc()); |
| 4838 | } else { |
| 4839 | // Look for a destructor known with the given name. |
| 4840 | CXXScopeSpec SS; |
| 4841 | if (Qualifier) { |
| 4842 | SS.setScopeRep(Qualifier); |
| 4843 | SS.setRange(E->getQualifierRange()); |
| 4844 | } |
| 4845 | |
| 4846 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 4847 | *E->getDestroyedTypeIdentifier(), |
| 4848 | E->getDestroyedTypeLoc(), |
| 4849 | /*Scope=*/0, |
| 4850 | SS, ObjectTypePtr, |
| 4851 | false); |
| 4852 | if (!T) |
| 4853 | return SemaRef.ExprError(); |
| 4854 | |
| 4855 | Destroyed |
| 4856 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 4857 | E->getDestroyedTypeLoc()); |
| 4858 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4859 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4860 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4861 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4862 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 4863 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4864 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4865 | return SemaRef.ExprError(); |
| 4866 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4867 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4868 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4869 | E->getOperatorLoc(), |
| 4870 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4871 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4872 | E->getQualifierRange(), |
| 4873 | ScopeTypeInfo, |
| 4874 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 4875 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4876 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4877 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4878 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4879 | template<typename Derived> |
| 4880 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4881 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4882 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4883 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4884 | |
| 4885 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4886 | Sema::LookupOrdinaryName); |
| 4887 | |
| 4888 | // Transform all the decls. |
| 4889 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4890 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4891 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 4892 | getDerived().TransformDecl(Old->getNameLoc(), |
| 4893 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4894 | if (!InstD) { |
| 4895 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4896 | // This can happen because of dependent hiding. |
| 4897 | if (isa<UsingShadowDecl>(*I)) |
| 4898 | continue; |
| 4899 | else |
| 4900 | return SemaRef.ExprError(); |
| 4901 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4902 | |
| 4903 | // Expand using declarations. |
| 4904 | if (isa<UsingDecl>(InstD)) { |
| 4905 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4906 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4907 | E = UD->shadow_end(); I != E; ++I) |
| 4908 | R.addDecl(*I); |
| 4909 | continue; |
| 4910 | } |
| 4911 | |
| 4912 | R.addDecl(InstD); |
| 4913 | } |
| 4914 | |
| 4915 | // Resolve a kind, but don't do any further analysis. If it's |
| 4916 | // ambiguous, the callee needs to deal with it. |
| 4917 | R.resolveKind(); |
| 4918 | |
| 4919 | // Rebuild the nested-name qualifier, if present. |
| 4920 | CXXScopeSpec SS; |
| 4921 | NestedNameSpecifier *Qualifier = 0; |
| 4922 | if (Old->getQualifier()) { |
| 4923 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4924 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4925 | if (!Qualifier) |
| 4926 | return SemaRef.ExprError(); |
| 4927 | |
| 4928 | SS.setScopeRep(Qualifier); |
| 4929 | SS.setRange(Old->getQualifierRange()); |
| 4930 | } |
| 4931 | |
| 4932 | // If we have no template arguments, it's a normal declaration name. |
| 4933 | if (!Old->hasExplicitTemplateArgs()) |
| 4934 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4935 | |
| 4936 | // If we have template arguments, rebuild them, then rebuild the |
| 4937 | // templateid expression. |
| 4938 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4939 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4940 | TemplateArgumentLoc Loc; |
| 4941 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4942 | return SemaRef.ExprError(); |
| 4943 | TransArgs.addArgument(Loc); |
| 4944 | } |
| 4945 | |
| 4946 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4947 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4949 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4950 | template<typename Derived> |
| 4951 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4952 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4953 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4954 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4955 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4956 | if (T.isNull()) |
| 4957 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4959 | if (!getDerived().AlwaysRebuild() && |
| 4960 | T == E->getQueriedType()) |
| 4961 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4963 | // FIXME: Bad location information |
| 4964 | SourceLocation FakeLParenLoc |
| 4965 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
| 4967 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4968 | E->getLocStart(), |
| 4969 | /*FIXME:*/FakeLParenLoc, |
| 4970 | T, |
| 4971 | E->getLocEnd()); |
| 4972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4973 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4974 | template<typename Derived> |
| 4975 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4976 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4977 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4978 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4979 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4980 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4981 | if (!NNS) |
| 4982 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4983 | |
| 4984 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4985 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4986 | if (!Name) |
| 4987 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4989 | if (!E->hasExplicitTemplateArgs()) { |
| 4990 | if (!getDerived().AlwaysRebuild() && |
| 4991 | NNS == E->getQualifier() && |
| 4992 | Name == E->getDeclName()) |
| 4993 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4994 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4995 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4996 | E->getQualifierRange(), |
| 4997 | Name, E->getLocation(), |
| 4998 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4999 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5000 | |
| 5001 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5002 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5003 | TemplateArgumentLoc Loc; |
| 5004 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5005 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5006 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5009 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5010 | E->getQualifierRange(), |
| 5011 | Name, E->getLocation(), |
| 5012 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | template<typename Derived> |
| 5016 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5017 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5018 | // CXXConstructExprs are always implicit, so when we have a |
| 5019 | // 1-argument construction we just transform that argument. |
| 5020 | if (E->getNumArgs() == 1 || |
| 5021 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5022 | return getDerived().TransformExpr(E->getArg(0)); |
| 5023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5025 | |
| 5026 | QualType T = getDerived().TransformType(E->getType()); |
| 5027 | if (T.isNull()) |
| 5028 | return SemaRef.ExprError(); |
| 5029 | |
| 5030 | CXXConstructorDecl *Constructor |
| 5031 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5032 | getDerived().TransformDecl(E->getLocStart(), |
| 5033 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5034 | if (!Constructor) |
| 5035 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5037 | bool ArgumentChanged = false; |
| 5038 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5039 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5040 | ArgEnd = E->arg_end(); |
| 5041 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5042 | if (getDerived().DropCallArgument(*Arg)) { |
| 5043 | ArgumentChanged = true; |
| 5044 | break; |
| 5045 | } |
| 5046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5047 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5048 | if (TransArg.isInvalid()) |
| 5049 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5051 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5052 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5053 | } |
| 5054 | |
| 5055 | if (!getDerived().AlwaysRebuild() && |
| 5056 | T == E->getType() && |
| 5057 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5058 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5059 | // Mark the constructor as referenced. |
| 5060 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5061 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5062 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5063 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5065 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5066 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | move_arg(Args)); |
| 5068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5069 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5070 | /// \brief Transform a C++ temporary-binding expression. |
| 5071 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5072 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5073 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5074 | template<typename Derived> |
| 5075 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5076 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5077 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5080 | /// \brief Transform a C++ reference-binding expression. |
| 5081 | /// |
| 5082 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5083 | /// transform the subexpression and return that. |
| 5084 | template<typename Derived> |
| 5085 | Sema::OwningExprResult |
| 5086 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5087 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5088 | } |
| 5089 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5090 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5091 | /// be destroyed after the expression is evaluated. |
| 5092 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5093 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5094 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | template<typename Derived> |
| 5096 | Sema::OwningExprResult |
| 5097 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5098 | CXXExprWithTemporaries *E) { |
| 5099 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5102 | template<typename Derived> |
| 5103 | Sema::OwningExprResult |
| 5104 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5105 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5106 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5107 | QualType T = getDerived().TransformType(E->getType()); |
| 5108 | if (T.isNull()) |
| 5109 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5110 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5111 | CXXConstructorDecl *Constructor |
| 5112 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5113 | getDerived().TransformDecl(E->getLocStart(), |
| 5114 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | if (!Constructor) |
| 5116 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5117 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5118 | bool ArgumentChanged = false; |
| 5119 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5120 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5121 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5122 | ArgEnd = E->arg_end(); |
| 5123 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5124 | if (getDerived().DropCallArgument(*Arg)) { |
| 5125 | ArgumentChanged = true; |
| 5126 | break; |
| 5127 | } |
| 5128 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5129 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5130 | if (TransArg.isInvalid()) |
| 5131 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5133 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5134 | Args.push_back((Expr *)TransArg.release()); |
| 5135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5137 | if (!getDerived().AlwaysRebuild() && |
| 5138 | T == E->getType() && |
| 5139 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5140 | !ArgumentChanged) { |
| 5141 | // FIXME: Instantiation-specific |
| 5142 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5143 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5145 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5146 | // FIXME: Bogus location information |
| 5147 | SourceLocation CommaLoc; |
| 5148 | if (Args.size() > 1) { |
| 5149 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5151 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5152 | } |
| 5153 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5154 | T, |
| 5155 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5156 | move_arg(Args), |
| 5157 | &CommaLoc, |
| 5158 | E->getLocEnd()); |
| 5159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | template<typename Derived> |
| 5162 | Sema::OwningExprResult |
| 5163 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5164 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5165 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5166 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5167 | if (T.isNull()) |
| 5168 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5170 | bool ArgumentChanged = false; |
| 5171 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5172 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5173 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5174 | ArgEnd = E->arg_end(); |
| 5175 | Arg != ArgEnd; ++Arg) { |
| 5176 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5177 | if (TransArg.isInvalid()) |
| 5178 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5181 | FakeCommaLocs.push_back( |
| 5182 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5183 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5184 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5186 | if (!getDerived().AlwaysRebuild() && |
| 5187 | T == E->getTypeAsWritten() && |
| 5188 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | return SemaRef.Owned(E->Retain()); |
| 5190 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5191 | // FIXME: we're faking the locations of the commas |
| 5192 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5193 | T, |
| 5194 | E->getLParenLoc(), |
| 5195 | move_arg(Args), |
| 5196 | FakeCommaLocs.data(), |
| 5197 | E->getRParenLoc()); |
| 5198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5200 | template<typename Derived> |
| 5201 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5202 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5203 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5205 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5206 | Expr *OldBase; |
| 5207 | QualType BaseType; |
| 5208 | QualType ObjectType; |
| 5209 | if (!E->isImplicitAccess()) { |
| 5210 | OldBase = E->getBase(); |
| 5211 | Base = getDerived().TransformExpr(OldBase); |
| 5212 | if (Base.isInvalid()) |
| 5213 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5214 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5215 | // Start the member reference and compute the object's type. |
| 5216 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5217 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5218 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5219 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5220 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5221 | ObjectTy, |
| 5222 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5223 | if (Base.isInvalid()) |
| 5224 | return SemaRef.ExprError(); |
| 5225 | |
| 5226 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5227 | BaseType = ((Expr*) Base.get())->getType(); |
| 5228 | } else { |
| 5229 | OldBase = 0; |
| 5230 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5231 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5232 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5233 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5234 | // Transform the first part of the nested-name-specifier that qualifies |
| 5235 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5236 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5237 | = getDerived().TransformFirstQualifierInScope( |
| 5238 | E->getFirstQualifierFoundInScope(), |
| 5239 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5240 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5241 | NestedNameSpecifier *Qualifier = 0; |
| 5242 | if (E->getQualifier()) { |
| 5243 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5244 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5245 | ObjectType, |
| 5246 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5247 | if (!Qualifier) |
| 5248 | return SemaRef.ExprError(); |
| 5249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5250 | |
| 5251 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5252 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5253 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5254 | if (!Name) |
| 5255 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5256 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5257 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5258 | // This is a reference to a member without an explicitly-specified |
| 5259 | // template argument list. Optimize for this common case. |
| 5260 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5261 | Base.get() == OldBase && |
| 5262 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5263 | Qualifier == E->getQualifier() && |
| 5264 | Name == E->getMember() && |
| 5265 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | return SemaRef.Owned(E->Retain()); |
| 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 | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5270 | E->isArrow(), |
| 5271 | E->getOperatorLoc(), |
| 5272 | Qualifier, |
| 5273 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5274 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5275 | Name, |
| 5276 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5277 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5278 | } |
| 5279 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5280 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5281 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5282 | TemplateArgumentLoc Loc; |
| 5283 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5284 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5285 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5288 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5289 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5290 | E->isArrow(), |
| 5291 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5292 | Qualifier, |
| 5293 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5294 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5295 | Name, |
| 5296 | E->getMemberLoc(), |
| 5297 | &TransArgs); |
| 5298 | } |
| 5299 | |
| 5300 | template<typename Derived> |
| 5301 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5302 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5303 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5304 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5305 | QualType BaseType; |
| 5306 | if (!Old->isImplicitAccess()) { |
| 5307 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5308 | if (Base.isInvalid()) |
| 5309 | return SemaRef.ExprError(); |
| 5310 | BaseType = ((Expr*) Base.get())->getType(); |
| 5311 | } else { |
| 5312 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5313 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5314 | |
| 5315 | NestedNameSpecifier *Qualifier = 0; |
| 5316 | if (Old->getQualifier()) { |
| 5317 | Qualifier |
| 5318 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5319 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5320 | if (Qualifier == 0) |
| 5321 | return SemaRef.ExprError(); |
| 5322 | } |
| 5323 | |
| 5324 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5325 | Sema::LookupOrdinaryName); |
| 5326 | |
| 5327 | // Transform all the decls. |
| 5328 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5329 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5330 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5331 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5332 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5333 | if (!InstD) { |
| 5334 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5335 | // This can happen because of dependent hiding. |
| 5336 | if (isa<UsingShadowDecl>(*I)) |
| 5337 | continue; |
| 5338 | else |
| 5339 | return SemaRef.ExprError(); |
| 5340 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5341 | |
| 5342 | // Expand using declarations. |
| 5343 | if (isa<UsingDecl>(InstD)) { |
| 5344 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5345 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5346 | E = UD->shadow_end(); I != E; ++I) |
| 5347 | R.addDecl(*I); |
| 5348 | continue; |
| 5349 | } |
| 5350 | |
| 5351 | R.addDecl(InstD); |
| 5352 | } |
| 5353 | |
| 5354 | R.resolveKind(); |
| 5355 | |
| 5356 | TemplateArgumentListInfo TransArgs; |
| 5357 | if (Old->hasExplicitTemplateArgs()) { |
| 5358 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5359 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5360 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5361 | TemplateArgumentLoc Loc; |
| 5362 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5363 | Loc)) |
| 5364 | return SemaRef.ExprError(); |
| 5365 | TransArgs.addArgument(Loc); |
| 5366 | } |
| 5367 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5368 | |
| 5369 | // FIXME: to do this check properly, we will need to preserve the |
| 5370 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5371 | // base (and therefore couldn't do the check) and a |
| 5372 | // nested-name-qualifier (and therefore could do the lookup). |
| 5373 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5374 | |
| 5375 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5376 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5377 | Old->getOperatorLoc(), |
| 5378 | Old->isArrow(), |
| 5379 | Qualifier, |
| 5380 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5381 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5382 | R, |
| 5383 | (Old->hasExplicitTemplateArgs() |
| 5384 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | template<typename Derived> |
| 5388 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5389 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5393 | template<typename Derived> |
| 5394 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5395 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5396 | // FIXME: poor source location |
| 5397 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5398 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5399 | if (EncodedType.isNull()) |
| 5400 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5402 | if (!getDerived().AlwaysRebuild() && |
| 5403 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5404 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5405 | |
| 5406 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5407 | EncodedType, |
| 5408 | E->getRParenLoc()); |
| 5409 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5411 | template<typename Derived> |
| 5412 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5413 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5414 | // FIXME: Implement this! |
| 5415 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5416 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5417 | } |
| 5418 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5419 | template<typename Derived> |
| 5420 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5421 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5422 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5423 | } |
| 5424 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5425 | template<typename Derived> |
| 5426 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5427 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5428 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5429 | = cast_or_null<ObjCProtocolDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5430 | getDerived().TransformDecl(E->getLocStart(), |
| 5431 | E->getProtocol())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5432 | if (!Protocol) |
| 5433 | return SemaRef.ExprError(); |
| 5434 | |
| 5435 | if (!getDerived().AlwaysRebuild() && |
| 5436 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5437 | return SemaRef.Owned(E->Retain()); |
| 5438 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5439 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5440 | E->getAtLoc(), |
| 5441 | /*FIXME:*/E->getAtLoc(), |
| 5442 | /*FIXME:*/E->getAtLoc(), |
| 5443 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5447 | template<typename Derived> |
| 5448 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5449 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5450 | // FIXME: Implement this! |
| 5451 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5455 | template<typename Derived> |
| 5456 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5457 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5458 | // FIXME: Implement this! |
| 5459 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5461 | } |
| 5462 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | template<typename Derived> |
| 5464 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5465 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5466 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5467 | // FIXME: Implement this! |
| 5468 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5472 | template<typename Derived> |
| 5473 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5474 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5475 | // FIXME: Implement this! |
| 5476 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5477 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5478 | } |
| 5479 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5480 | template<typename Derived> |
| 5481 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5482 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5483 | // FIXME: Implement this! |
| 5484 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5485 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5486 | } |
| 5487 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | template<typename Derived> |
| 5489 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5490 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5491 | bool ArgumentChanged = false; |
| 5492 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5493 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5494 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5495 | if (SubExpr.isInvalid()) |
| 5496 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5497 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5498 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5499 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5500 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | if (!getDerived().AlwaysRebuild() && |
| 5503 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | return SemaRef.Owned(E->Retain()); |
| 5505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5506 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5507 | move_arg(SubExprs), |
| 5508 | E->getRParenLoc()); |
| 5509 | } |
| 5510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | template<typename Derived> |
| 5512 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5513 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5514 | // FIXME: Implement this! |
| 5515 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5516 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5519 | template<typename Derived> |
| 5520 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5521 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5522 | // FIXME: Implement this! |
| 5523 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5524 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5525 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5526 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5527 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5528 | // Type reconstruction |
| 5529 | //===----------------------------------------------------------------------===// |
| 5530 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5531 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5532 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5533 | SourceLocation Star) { |
| 5534 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5535 | getDerived().getBaseEntity()); |
| 5536 | } |
| 5537 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5538 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5539 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5540 | SourceLocation Star) { |
| 5541 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5542 | getDerived().getBaseEntity()); |
| 5543 | } |
| 5544 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | template<typename Derived> |
| 5546 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5547 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5548 | bool WrittenAsLValue, |
| 5549 | SourceLocation Sigil) { |
| 5550 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5551 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5555 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5556 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5557 | QualType ClassType, |
| 5558 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5559 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5560 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5564 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5565 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5566 | SourceLocation Sigil) { |
| 5567 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5568 | getDerived().getBaseEntity()); |
| 5569 | } |
| 5570 | |
| 5571 | template<typename Derived> |
| 5572 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5573 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5574 | ArrayType::ArraySizeModifier SizeMod, |
| 5575 | const llvm::APInt *Size, |
| 5576 | Expr *SizeExpr, |
| 5577 | unsigned IndexTypeQuals, |
| 5578 | SourceRange BracketsRange) { |
| 5579 | if (SizeExpr || !Size) |
| 5580 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5581 | IndexTypeQuals, BracketsRange, |
| 5582 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | |
| 5584 | QualType Types[] = { |
| 5585 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5586 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5587 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5588 | }; |
| 5589 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5590 | QualType SizeType; |
| 5591 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5592 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5593 | SizeType = Types[I]; |
| 5594 | break; |
| 5595 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5597 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5598 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5599 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5600 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5601 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5602 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5603 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5604 | QualType |
| 5605 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5606 | ArrayType::ArraySizeModifier SizeMod, |
| 5607 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5608 | unsigned IndexTypeQuals, |
| 5609 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5610 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5611 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5617 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5618 | unsigned IndexTypeQuals, |
| 5619 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5621 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5623 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5624 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5625 | QualType |
| 5626 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5627 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5628 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5629 | unsigned IndexTypeQuals, |
| 5630 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5632 | SizeExpr.takeAs<Expr>(), |
| 5633 | IndexTypeQuals, BracketsRange); |
| 5634 | } |
| 5635 | |
| 5636 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | QualType |
| 5638 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5639 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5640 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5641 | unsigned IndexTypeQuals, |
| 5642 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5644 | SizeExpr.takeAs<Expr>(), |
| 5645 | IndexTypeQuals, BracketsRange); |
| 5646 | } |
| 5647 | |
| 5648 | template<typename Derived> |
| 5649 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5650 | unsigned NumElements, |
| 5651 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5652 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5653 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5654 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5657 | template<typename Derived> |
| 5658 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5659 | unsigned NumElements, |
| 5660 | SourceLocation AttributeLoc) { |
| 5661 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5662 | NumElements, true); |
| 5663 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5665 | AttributeLoc); |
| 5666 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5667 | AttributeLoc); |
| 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> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | QualType |
| 5672 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5673 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5674 | SourceLocation AttributeLoc) { |
| 5675 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5677 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5678 | template<typename Derived> |
| 5679 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5680 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5681 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5682 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5683 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5684 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5685 | Quals, |
| 5686 | getDerived().getBaseLocation(), |
| 5687 | getDerived().getBaseEntity()); |
| 5688 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5690 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5691 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5692 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5693 | } |
| 5694 | |
| 5695 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5696 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5697 | assert(D && "no decl found"); |
| 5698 | if (D->isInvalidDecl()) return QualType(); |
| 5699 | |
| 5700 | TypeDecl *Ty; |
| 5701 | if (isa<UsingDecl>(D)) { |
| 5702 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5703 | assert(Using->isTypeName() && |
| 5704 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5705 | |
| 5706 | // A valid resolved using typename decl points to exactly one type decl. |
| 5707 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5708 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5709 | |
| 5710 | } else { |
| 5711 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5712 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5713 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5714 | } |
| 5715 | |
| 5716 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5717 | } |
| 5718 | |
| 5719 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5720 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5721 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5722 | } |
| 5723 | |
| 5724 | template<typename Derived> |
| 5725 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5726 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5727 | } |
| 5728 | |
| 5729 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5730 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5731 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5732 | } |
| 5733 | |
| 5734 | template<typename Derived> |
| 5735 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5736 | TemplateName Template, |
| 5737 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5738 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5739 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5742 | template<typename Derived> |
| 5743 | NestedNameSpecifier * |
| 5744 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5745 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5746 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5747 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5748 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5749 | CXXScopeSpec SS; |
| 5750 | // FIXME: The source location information is all wrong. |
| 5751 | SS.setRange(Range); |
| 5752 | SS.setScopeRep(Prefix); |
| 5753 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5755 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5756 | ObjectType, |
| 5757 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5758 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | template<typename Derived> |
| 5762 | NestedNameSpecifier * |
| 5763 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5764 | SourceRange Range, |
| 5765 | NamespaceDecl *NS) { |
| 5766 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5767 | } |
| 5768 | |
| 5769 | template<typename Derived> |
| 5770 | NestedNameSpecifier * |
| 5771 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5772 | SourceRange Range, |
| 5773 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5774 | QualType T) { |
| 5775 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5776 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5777 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5778 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5779 | T.getTypePtr()); |
| 5780 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5781 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5782 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5783 | return 0; |
| 5784 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5785 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5786 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5787 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5788 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5789 | bool TemplateKW, |
| 5790 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5791 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5792 | Template); |
| 5793 | } |
| 5794 | |
| 5795 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5796 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5797 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5798 | const IdentifierInfo &II, |
| 5799 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5800 | CXXScopeSpec SS; |
| 5801 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5802 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5803 | UnqualifiedId Name; |
| 5804 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5805 | return getSema().ActOnDependentTemplateName( |
| 5806 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5807 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5808 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5809 | ObjectType.getAsOpaquePtr(), |
| 5810 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5811 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5814 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5815 | TemplateName |
| 5816 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5817 | OverloadedOperatorKind Operator, |
| 5818 | QualType ObjectType) { |
| 5819 | CXXScopeSpec SS; |
| 5820 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5821 | SS.setScopeRep(Qualifier); |
| 5822 | UnqualifiedId Name; |
| 5823 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5824 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5825 | Operator, SymbolLocations); |
| 5826 | return getSema().ActOnDependentTemplateName( |
| 5827 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5828 | SS, |
| 5829 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5830 | ObjectType.getAsOpaquePtr(), |
| 5831 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5832 | .template getAsVal<TemplateName>(); |
| 5833 | } |
| 5834 | |
| 5835 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5836 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5837 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5838 | SourceLocation OpLoc, |
| 5839 | ExprArg Callee, |
| 5840 | ExprArg First, |
| 5841 | ExprArg Second) { |
| 5842 | Expr *FirstExpr = (Expr *)First.get(); |
| 5843 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5844 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5845 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5846 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5847 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5848 | if (Op == OO_Subscript) { |
| 5849 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5850 | !SecondExpr->getType()->isOverloadableType()) |
| 5851 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5852 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5853 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5854 | } else if (Op == OO_Arrow) { |
| 5855 | // -> is never a builtin operation. |
| 5856 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5857 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5858 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5859 | // The argument is not of overloadable type, so try to create a |
| 5860 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5861 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5862 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5863 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5864 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5865 | } |
| 5866 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5867 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5868 | !SecondExpr->getType()->isOverloadableType()) { |
| 5869 | // Neither of the arguments is an overloadable type, so try to |
| 5870 | // create a built-in binary operation. |
| 5871 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5873 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5874 | if (Result.isInvalid()) |
| 5875 | return SemaRef.ExprError(); |
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 | First.release(); |
| 5878 | Second.release(); |
| 5879 | return move(Result); |
| 5880 | } |
| 5881 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5882 | |
| 5883 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5884 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5885 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5886 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5887 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5888 | assert(ULE->requiresADL()); |
| 5889 | |
| 5890 | // FIXME: Do we have to check |
| 5891 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5892 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5893 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5894 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5895 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5896 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5897 | // Add any functions found via argument-dependent lookup. |
| 5898 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5899 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5900 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5901 | // Create the overloaded operator invocation for unary operators. |
| 5902 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5903 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5904 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5905 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5907 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5908 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5909 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5910 | OpLoc, |
| 5911 | move(First), |
| 5912 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5913 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5914 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5915 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5916 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5917 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5918 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5919 | if (Result.isInvalid()) |
| 5920 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5921 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5922 | First.release(); |
| 5923 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5924 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5925 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5926 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5927 | template<typename Derived> |
| 5928 | Sema::OwningExprResult |
| 5929 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 5930 | SourceLocation OperatorLoc, |
| 5931 | bool isArrow, |
| 5932 | NestedNameSpecifier *Qualifier, |
| 5933 | SourceRange QualifierRange, |
| 5934 | TypeSourceInfo *ScopeType, |
| 5935 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5936 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5937 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5938 | CXXScopeSpec SS; |
| 5939 | if (Qualifier) { |
| 5940 | SS.setRange(QualifierRange); |
| 5941 | SS.setScopeRep(Qualifier); |
| 5942 | } |
| 5943 | |
| 5944 | Expr *BaseE = (Expr *)Base.get(); |
| 5945 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5946 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5947 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 5948 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 5949 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 5950 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5951 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 5952 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 5953 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5954 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5955 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5956 | /*FIXME?*/true); |
| 5957 | } |
| 5958 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5959 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5960 | DeclarationName Name |
| 5961 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 5962 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 5963 | |
| 5964 | // FIXME: the ScopeType should be tacked onto SS. |
| 5965 | |
| 5966 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 5967 | OperatorLoc, isArrow, |
| 5968 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5969 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5970 | /*TemplateArgs*/ 0); |
| 5971 | } |
| 5972 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5973 | } // end namespace clang |
| 5974 | |
| 5975 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |