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); |
Zhongxing Xu | 105dfb5 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 347 | #define ABSTRACT_EXPR(Node, Parent) |
| 348 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Build a new pointer type given its pointee type. |
| 351 | /// |
| 352 | /// By default, performs semantic analysis when building the pointer type. |
| 353 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | |
| 356 | /// \brief Build a new block pointer type given its pointee type. |
| 357 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | /// By default, performs semantic analysis when building the |
| 365 | /// reference type. Subclasses may override this routine to provide |
| 366 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | /// \param LValue whether the type was written with an lvalue sigil |
| 369 | /// or an rvalue sigil. |
| 370 | QualType RebuildReferenceType(QualType ReferentType, |
| 371 | bool LValue, |
| 372 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 374 | /// \brief Build a new member pointer type given the pointee type and the |
| 375 | /// class type it refers into. |
| 376 | /// |
| 377 | /// By default, performs semantic analysis when building the member pointer |
| 378 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | /// \brief Build a new array type given the element type, size |
| 383 | /// modifier, size of the array (if known), size expression, and index type |
| 384 | /// qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | QualType RebuildArrayType(QualType ElementType, |
| 390 | ArrayType::ArraySizeModifier SizeMod, |
| 391 | const llvm::APInt *Size, |
| 392 | Expr *SizeExpr, |
| 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new constant array type given the element type, size |
| 397 | /// modifier, (known) size of the array, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// \brief Build a new incomplete array type given the element type, size |
| 408 | /// modifier, and index type qualifiers. |
| 409 | /// |
| 410 | /// By default, performs semantic analysis when building the array type. |
| 411 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 429 | /// size modifier, size expression, and index type qualifiers. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the array type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | unsigned IndexTypeQuals, |
| 437 | SourceRange BracketsRange); |
| 438 | |
| 439 | /// \brief Build a new vector type given the element type and |
| 440 | /// number of elements. |
| 441 | /// |
| 442 | /// By default, performs semantic analysis when building the vector type. |
| 443 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Build a new extended vector type given the element type and |
| 448 | /// number of elements. |
| 449 | /// |
| 450 | /// By default, performs semantic analysis when building the vector type. |
| 451 | /// Subclasses may override this routine to provide different behavior. |
| 452 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 453 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// given the element type and number of elements. |
| 457 | /// |
| 458 | /// By default, performs semantic analysis when building the vector type. |
| 459 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new function type. |
| 465 | /// |
| 466 | /// By default, performs semantic analysis when building the function type. |
| 467 | /// Subclasses may override this routine to provide different behavior. |
| 468 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 473 | /// \brief Build a new unprototyped function type. |
| 474 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 475 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 476 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 477 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 478 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 479 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Build a new typedef type. |
| 481 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 482 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 483 | } |
| 484 | |
| 485 | /// \brief Build a new class/struct/union type. |
| 486 | QualType RebuildRecordType(RecordDecl *Record) { |
| 487 | return SemaRef.Context.getTypeDeclType(Record); |
| 488 | } |
| 489 | |
| 490 | /// \brief Build a new Enum type. |
| 491 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 492 | return SemaRef.Context.getTypeDeclType(Enum); |
| 493 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 494 | |
| 495 | /// \brief Build a new elaborated type. |
| 496 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 497 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
| 500 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | /// |
| 502 | /// By default, performs semantic analysis when building the typeof type. |
| 503 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 504 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, builds a new TypeOfType with the given underlying type. |
| 509 | QualType RebuildTypeOfType(QualType Underlying); |
| 510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// |
| 513 | /// By default, performs semantic analysis when building the decltype type. |
| 514 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 515 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// \brief Build a new template specialization type. |
| 518 | /// |
| 519 | /// By default, performs semantic analysis when building the template |
| 520 | /// specialization type. Subclasses may override this routine to provide |
| 521 | /// different behavior. |
| 522 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 524 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// \brief Build a new qualified name type. |
| 527 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | /// By default, builds a new QualifiedNameType type from the |
| 529 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | /// this routine to provide different behavior. |
| 531 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 532 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | |
| 535 | /// \brief Build a new typename type that refers to a template-id. |
| 536 | /// |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 537 | /// By default, builds a new DependentNameType type from the |
| 538 | /// nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 541 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 542 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 543 | if (NNS->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 544 | // If the name is still dependent, just build a new dependent name type. |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 548 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 552 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 555 | |
| 556 | /// \brief Build a new typename type that refers to an identifier. |
| 557 | /// |
| 558 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 561 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 562 | NestedNameSpecifier *NNS, |
| 563 | const IdentifierInfo *Id, |
| 564 | SourceRange SR) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 565 | CXXScopeSpec SS; |
| 566 | SS.setScopeRep(NNS); |
| 567 | |
| 568 | if (NNS->isDependent()) { |
| 569 | // If the name is still dependent, just build a new dependent name type. |
| 570 | if (!SemaRef.computeDeclContext(SS)) |
| 571 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 572 | } |
| 573 | |
| 574 | TagDecl::TagKind Kind = TagDecl::TK_enum; |
| 575 | switch (Keyword) { |
| 576 | case ETK_None: |
| 577 | // FIXME: Note the lack of the "typename" specifier! |
| 578 | // Fall through |
| 579 | case ETK_Typename: |
| 580 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
| 581 | |
| 582 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 583 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 584 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 585 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 586 | } |
| 587 | |
| 588 | // We had a dependent elaborated-type-specifier that as been transformed |
| 589 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 590 | // referring to. |
| 591 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 592 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 593 | if (!DC) |
| 594 | return QualType(); |
| 595 | |
| 596 | TagDecl *Tag = 0; |
| 597 | SemaRef.LookupQualifiedName(Result, DC); |
| 598 | switch (Result.getResultKind()) { |
| 599 | case LookupResult::NotFound: |
| 600 | case LookupResult::NotFoundInCurrentInstantiation: |
| 601 | break; |
| 602 | |
| 603 | case LookupResult::Found: |
| 604 | Tag = Result.getAsSingle<TagDecl>(); |
| 605 | break; |
| 606 | |
| 607 | case LookupResult::FoundOverloaded: |
| 608 | case LookupResult::FoundUnresolvedValue: |
| 609 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 610 | return QualType(); |
| 611 | |
| 612 | case LookupResult::Ambiguous: |
| 613 | // Let the LookupResult structure handle ambiguities. |
| 614 | return QualType(); |
| 615 | } |
| 616 | |
| 617 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 618 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 619 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 620 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 621 | return QualType(); |
| 622 | } |
| 623 | |
| 624 | // FIXME: Terrible location information |
| 625 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 626 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 627 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 628 | return QualType(); |
| 629 | } |
| 630 | |
| 631 | // Build the elaborated-type-specifier type. |
| 632 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 633 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 634 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 637 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 638 | /// identifier that names the next step in the nested-name-specifier. |
| 639 | /// |
| 640 | /// By default, performs semantic analysis when building the new |
| 641 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 642 | /// different behavior. |
| 643 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 644 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 645 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 646 | QualType ObjectType, |
| 647 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 648 | |
| 649 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 650 | /// namespace named in the next step in the nested-name-specifier. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis when building the new |
| 653 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 654 | /// different behavior. |
| 655 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 656 | SourceRange Range, |
| 657 | NamespaceDecl *NS); |
| 658 | |
| 659 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 660 | /// type named in the next step in the nested-name-specifier. |
| 661 | /// |
| 662 | /// By default, performs semantic analysis when building the new |
| 663 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 664 | /// different behavior. |
| 665 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 666 | SourceRange Range, |
| 667 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 668 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 669 | |
| 670 | /// \brief Build a new template name given a nested name specifier, a flag |
| 671 | /// indicating whether the "template" keyword was provided, and the template |
| 672 | /// that the template name refers to. |
| 673 | /// |
| 674 | /// By default, builds the new template name directly. Subclasses may override |
| 675 | /// this routine to provide different behavior. |
| 676 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 677 | bool TemplateKW, |
| 678 | TemplateDecl *Template); |
| 679 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 680 | /// \brief Build a new template name given a nested name specifier and the |
| 681 | /// name that is referred to as a template. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis to determine whether the name can |
| 684 | /// be resolved to a specific template, then builds the appropriate kind of |
| 685 | /// template name. Subclasses may override this routine to provide different |
| 686 | /// behavior. |
| 687 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 688 | const IdentifierInfo &II, |
| 689 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 691 | /// \brief Build a new template name given a nested name specifier and the |
| 692 | /// overloaded operator name that is referred to as a template. |
| 693 | /// |
| 694 | /// By default, performs semantic analysis to determine whether the name can |
| 695 | /// be resolved to a specific template, then builds the appropriate kind of |
| 696 | /// template name. Subclasses may override this routine to provide different |
| 697 | /// behavior. |
| 698 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 699 | OverloadedOperatorKind Operator, |
| 700 | QualType ObjectType); |
| 701 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 702 | /// \brief Build a new compound statement. |
| 703 | /// |
| 704 | /// By default, performs semantic analysis to build the new statement. |
| 705 | /// Subclasses may override this routine to provide different behavior. |
| 706 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 707 | MultiStmtArg Statements, |
| 708 | SourceLocation RBraceLoc, |
| 709 | bool IsStmtExpr) { |
| 710 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 711 | IsStmtExpr); |
| 712 | } |
| 713 | |
| 714 | /// \brief Build a new case statement. |
| 715 | /// |
| 716 | /// By default, performs semantic analysis to build the new statement. |
| 717 | /// Subclasses may override this routine to provide different behavior. |
| 718 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 719 | ExprArg LHS, |
| 720 | SourceLocation EllipsisLoc, |
| 721 | ExprArg RHS, |
| 722 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | ColonLoc); |
| 725 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | /// \brief Attach the body to a new case statement. |
| 728 | /// |
| 729 | /// By default, performs semantic analysis to build the new statement. |
| 730 | /// Subclasses may override this routine to provide different behavior. |
| 731 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 732 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 733 | return move(S); |
| 734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | /// \brief Build a new default statement. |
| 737 | /// |
| 738 | /// By default, performs semantic analysis to build the new statement. |
| 739 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | SourceLocation ColonLoc, |
| 742 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 744 | /*CurScope=*/0); |
| 745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | /// \brief Build a new label statement. |
| 748 | /// |
| 749 | /// By default, performs semantic analysis to build the new statement. |
| 750 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | IdentifierInfo *Id, |
| 753 | SourceLocation ColonLoc, |
| 754 | StmtArg SubStmt) { |
| 755 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 756 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | /// \brief Build a new "if" statement. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis to build the new statement. |
| 761 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 763 | VarDecl *CondVar, StmtArg Then, |
| 764 | SourceLocation ElseLoc, StmtArg Else) { |
| 765 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 766 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 769 | /// \brief Start building a new switch statement. |
| 770 | /// |
| 771 | /// By default, performs semantic analysis to build the new statement. |
| 772 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 773 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 774 | VarDecl *CondVar) { |
| 775 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 778 | /// \brief Attach the body to the switch statement. |
| 779 | /// |
| 780 | /// By default, performs semantic analysis to build the new statement. |
| 781 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 783 | StmtArg Switch, StmtArg Body) { |
| 784 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 785 | move(Body)); |
| 786 | } |
| 787 | |
| 788 | /// \brief Build a new while statement. |
| 789 | /// |
| 790 | /// By default, performs semantic analysis to build the new statement. |
| 791 | /// Subclasses may override this routine to provide different behavior. |
| 792 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 793 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 794 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 795 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 796 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 797 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 800 | /// \brief Build a new do-while statement. |
| 801 | /// |
| 802 | /// By default, performs semantic analysis to build the new statement. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
| 804 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 805 | SourceLocation WhileLoc, |
| 806 | SourceLocation LParenLoc, |
| 807 | ExprArg Cond, |
| 808 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 810 | move(Cond), RParenLoc); |
| 811 | } |
| 812 | |
| 813 | /// \brief Build a new for statement. |
| 814 | /// |
| 815 | /// By default, performs semantic analysis to build the new statement. |
| 816 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 819 | StmtArg Init, Sema::FullExprArg Cond, |
| 820 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 821 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 822 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 823 | DeclPtrTy::make(CondVar), |
| 824 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 825 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | /// \brief Build a new goto statement. |
| 828 | /// |
| 829 | /// By default, performs semantic analysis to build the new statement. |
| 830 | /// Subclasses may override this routine to provide different behavior. |
| 831 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 832 | SourceLocation LabelLoc, |
| 833 | LabelStmt *Label) { |
| 834 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 835 | } |
| 836 | |
| 837 | /// \brief Build a new indirect goto statement. |
| 838 | /// |
| 839 | /// By default, performs semantic analysis to build the new statement. |
| 840 | /// Subclasses may override this routine to provide different behavior. |
| 841 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 842 | SourceLocation StarLoc, |
| 843 | ExprArg Target) { |
| 844 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 847 | /// \brief Build a new return statement. |
| 848 | /// |
| 849 | /// By default, performs semantic analysis to build the new statement. |
| 850 | /// Subclasses may override this routine to provide different behavior. |
| 851 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 852 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 854 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 857 | /// \brief Build a new declaration statement. |
| 858 | /// |
| 859 | /// By default, performs semantic analysis to build the new statement. |
| 860 | /// Subclasses may override this routine to provide different behavior. |
| 861 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 863 | SourceLocation EndLoc) { |
| 864 | return getSema().Owned( |
| 865 | new (getSema().Context) DeclStmt( |
| 866 | DeclGroupRef::Create(getSema().Context, |
| 867 | Decls, NumDecls), |
| 868 | StartLoc, EndLoc)); |
| 869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 871 | /// \brief Build a new inline asm statement. |
| 872 | /// |
| 873 | /// By default, performs semantic analysis to build the new statement. |
| 874 | /// Subclasses may override this routine to provide different behavior. |
| 875 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 876 | bool IsSimple, |
| 877 | bool IsVolatile, |
| 878 | unsigned NumOutputs, |
| 879 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 880 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 881 | MultiExprArg Constraints, |
| 882 | MultiExprArg Exprs, |
| 883 | ExprArg AsmString, |
| 884 | MultiExprArg Clobbers, |
| 885 | SourceLocation RParenLoc, |
| 886 | bool MSAsm) { |
| 887 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 888 | NumInputs, Names, move(Constraints), |
| 889 | move(Exprs), move(AsmString), move(Clobbers), |
| 890 | RParenLoc, MSAsm); |
| 891 | } |
| 892 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 893 | /// \brief Build a new C++ exception declaration. |
| 894 | /// |
| 895 | /// By default, performs semantic analysis to build the new decaration. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 898 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 899 | IdentifierInfo *Name, |
| 900 | SourceLocation Loc, |
| 901 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 903 | TypeRange); |
| 904 | } |
| 905 | |
| 906 | /// \brief Build a new C++ catch statement. |
| 907 | /// |
| 908 | /// By default, performs semantic analysis to build the new statement. |
| 909 | /// Subclasses may override this routine to provide different behavior. |
| 910 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 911 | VarDecl *ExceptionDecl, |
| 912 | StmtArg Handler) { |
| 913 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 915 | Handler.takeAs<Stmt>())); |
| 916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 918 | /// \brief Build a new C++ try statement. |
| 919 | /// |
| 920 | /// By default, performs semantic analysis to build the new statement. |
| 921 | /// Subclasses may override this routine to provide different behavior. |
| 922 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 923 | StmtArg TryBlock, |
| 924 | MultiStmtArg Handlers) { |
| 925 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | /// \brief Build a new expression that references a declaration. |
| 929 | /// |
| 930 | /// By default, performs semantic analysis to build the new expression. |
| 931 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 932 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 933 | LookupResult &R, |
| 934 | bool RequiresADL) { |
| 935 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 936 | } |
| 937 | |
| 938 | |
| 939 | /// \brief Build a new expression that references a declaration. |
| 940 | /// |
| 941 | /// By default, performs semantic analysis to build the new expression. |
| 942 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 943 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 944 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 945 | ValueDecl *VD, SourceLocation Loc, |
| 946 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 947 | CXXScopeSpec SS; |
| 948 | SS.setScopeRep(Qualifier); |
| 949 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 950 | |
| 951 | // FIXME: loses template args. |
| 952 | |
| 953 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 956 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 957 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 958 | /// By default, performs semantic analysis to build the new expression. |
| 959 | /// Subclasses may override this routine to provide different behavior. |
| 960 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 961 | SourceLocation RParen) { |
| 962 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 963 | } |
| 964 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 965 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 967 | /// By default, performs semantic analysis to build the new expression. |
| 968 | /// Subclasses may override this routine to provide different behavior. |
| 969 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 970 | SourceLocation OperatorLoc, |
| 971 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 972 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 973 | SourceRange QualifierRange, |
| 974 | TypeSourceInfo *ScopeType, |
| 975 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 976 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 977 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 979 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 981 | /// By default, performs semantic analysis to build the new expression. |
| 982 | /// Subclasses may override this routine to provide different behavior. |
| 983 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 984 | UnaryOperator::Opcode Opc, |
| 985 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 986 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 989 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | /// By default, performs semantic analysis to build the new expression. |
| 992 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 993 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 994 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 995 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 996 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 999 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1000 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1002 | /// By default, performs semantic analysis to build the new expression. |
| 1003 | /// Subclasses may override this routine to provide different behavior. |
| 1004 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1005 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1007 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1008 | OpLoc, isSizeOf, R); |
| 1009 | if (Result.isInvalid()) |
| 1010 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1012 | SubExpr.release(); |
| 1013 | return move(Result); |
| 1014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1018 | /// By default, performs semantic analysis to build the new expression. |
| 1019 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1021 | SourceLocation LBracketLoc, |
| 1022 | ExprArg RHS, |
| 1023 | SourceLocation RBracketLoc) { |
| 1024 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1026 | RBracketLoc); |
| 1027 | } |
| 1028 | |
| 1029 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1031 | /// By default, performs semantic analysis to build the new expression. |
| 1032 | /// Subclasses may override this routine to provide different behavior. |
| 1033 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1034 | MultiExprArg Args, |
| 1035 | SourceLocation *CommaLocs, |
| 1036 | SourceLocation RParenLoc) { |
| 1037 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1038 | move(Args), CommaLocs, RParenLoc); |
| 1039 | } |
| 1040 | |
| 1041 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1042 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1043 | /// By default, performs semantic analysis to build the new expression. |
| 1044 | /// Subclasses may override this routine to provide different behavior. |
| 1045 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1047 | NestedNameSpecifier *Qualifier, |
| 1048 | SourceRange QualifierRange, |
| 1049 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1050 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1051 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1052 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1053 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1054 | if (!Member->getDeclName()) { |
| 1055 | // We have a reference to an unnamed field. |
| 1056 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1058 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1059 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1060 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1061 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1062 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1064 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1065 | Member, MemberLoc, |
| 1066 | cast<FieldDecl>(Member)->getType()); |
| 1067 | return getSema().Owned(ME); |
| 1068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1070 | CXXScopeSpec SS; |
| 1071 | if (Qualifier) { |
| 1072 | SS.setRange(QualifierRange); |
| 1073 | SS.setScopeRep(Qualifier); |
| 1074 | } |
| 1075 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1076 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1077 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1078 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1079 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1080 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1081 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1082 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1083 | R.resolveKind(); |
| 1084 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1085 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1086 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1087 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1088 | R, ExplicitTemplateArgs); |
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 binary operator 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 RebuildBinaryOperator(SourceLocation OpLoc, |
| 1096 | BinaryOperator::Opcode Opc, |
| 1097 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1098 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1099 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | /// By default, performs semantic analysis to build the new expression. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
| 1106 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1107 | SourceLocation QuestionLoc, |
| 1108 | ExprArg LHS, |
| 1109 | SourceLocation ColonLoc, |
| 1110 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1112 | move(LHS), move(RHS)); |
| 1113 | } |
| 1114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | /// By default, performs semantic analysis to build the new expression. |
| 1118 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1119 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1120 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1121 | SourceLocation RParenLoc, |
| 1122 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1123 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1124 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1129 | /// By default, performs semantic analysis to build the new expression. |
| 1130 | /// Subclasses may override this routine to provide different behavior. |
| 1131 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1132 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1133 | SourceLocation RParenLoc, |
| 1134 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1135 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1136 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 extended vector element access 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. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1144 | SourceLocation OpLoc, |
| 1145 | SourceLocation AccessorLoc, |
| 1146 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1147 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1148 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1149 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1150 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1151 | OpLoc, /*IsArrow*/ false, |
| 1152 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1153 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1154 | AccessorLoc, |
| 1155 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1158 | /// \brief Build a new initializer list expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1161 | /// Subclasses may override this routine to provide different behavior. |
| 1162 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1163 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1164 | SourceLocation RBraceLoc, |
| 1165 | QualType ResultTy) { |
| 1166 | OwningExprResult Result |
| 1167 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1168 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1169 | return move(Result); |
| 1170 | |
| 1171 | // Patch in the result type we were given, which may have been computed |
| 1172 | // when the initial InitListExpr was built. |
| 1173 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1174 | ILE->setType(ResultTy); |
| 1175 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1178 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1180 | /// By default, performs semantic analysis to build the new expression. |
| 1181 | /// Subclasses may override this routine to provide different behavior. |
| 1182 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1183 | MultiExprArg ArrayExprs, |
| 1184 | SourceLocation EqualOrColonLoc, |
| 1185 | bool GNUSyntax, |
| 1186 | ExprArg Init) { |
| 1187 | OwningExprResult Result |
| 1188 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1189 | move(Init)); |
| 1190 | if (Result.isInvalid()) |
| 1191 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | ArrayExprs.release(); |
| 1194 | return move(Result); |
| 1195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1197 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | /// By default, builds the implicit value initialization without performing |
| 1200 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1201 | /// different behavior. |
| 1202 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1203 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 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 \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | /// By default, performs semantic analysis to build the new expression. |
| 1209 | /// Subclasses may override this routine to provide different behavior. |
| 1210 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1211 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | RParenLoc); |
| 1214 | } |
| 1215 | |
| 1216 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | /// By default, performs semantic analysis to build the new expression. |
| 1219 | /// Subclasses may override this routine to provide different behavior. |
| 1220 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1221 | MultiExprArg SubExprs, |
| 1222 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1223 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1224 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1227 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | /// |
| 1229 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | /// rather than attempting to map the label statement itself. |
| 1231 | /// Subclasses may override this routine to provide different behavior. |
| 1232 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1233 | SourceLocation LabelLoc, |
| 1234 | LabelStmt *Label) { |
| 1235 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1236 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | /// By default, performs semantic analysis to build the new expression. |
| 1241 | /// Subclasses may override this routine to provide different behavior. |
| 1242 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1243 | StmtArg SubStmt, |
| 1244 | SourceLocation RParenLoc) { |
| 1245 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1246 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1249 | /// |
| 1250 | /// By default, performs semantic analysis to build the new expression. |
| 1251 | /// Subclasses may override this routine to provide different behavior. |
| 1252 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1253 | QualType T1, QualType T2, |
| 1254 | SourceLocation RParenLoc) { |
| 1255 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1256 | T1.getAsOpaquePtr(), |
| 1257 | T2.getAsOpaquePtr(), |
| 1258 | RParenLoc); |
| 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 | /// \brief Build a new __builtin_choose_expr expression. |
| 1262 | /// |
| 1263 | /// By default, performs semantic analysis to build the new expression. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| 1265 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1266 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1267 | SourceLocation RParenLoc) { |
| 1268 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1269 | move(Cond), move(LHS), move(RHS), |
| 1270 | RParenLoc); |
| 1271 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1272 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1273 | /// \brief Build a new overloaded operator call expression. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new expression. |
| 1276 | /// The semantic analysis provides the behavior of template instantiation, |
| 1277 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1278 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1280 | /// provide different behavior. |
| 1281 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1282 | SourceLocation OpLoc, |
| 1283 | ExprArg Callee, |
| 1284 | ExprArg First, |
| 1285 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | |
| 1287 | /// \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] | 1288 | /// reinterpret_cast. |
| 1289 | /// |
| 1290 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1294 | Stmt::StmtClass Class, |
| 1295 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1296 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1297 | SourceLocation RAngleLoc, |
| 1298 | SourceLocation LParenLoc, |
| 1299 | ExprArg SubExpr, |
| 1300 | SourceLocation RParenLoc) { |
| 1301 | switch (Class) { |
| 1302 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1303 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | move(SubExpr), RParenLoc); |
| 1306 | |
| 1307 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1308 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1313 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | RAngleLoc, LParenLoc, |
| 1315 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1318 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1319 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | default: |
| 1324 | assert(false && "Invalid C++ named cast"); |
| 1325 | break; |
| 1326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1328 | return getSema().ExprError(); |
| 1329 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | /// \brief Build a new C++ static_cast expression. |
| 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new expression. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1336 | SourceLocation LAngleLoc, |
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 RAngleLoc, |
| 1339 | SourceLocation LParenLoc, |
| 1340 | ExprArg SubExpr, |
| 1341 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1342 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1343 | TInfo, move(SubExpr), |
| 1344 | SourceRange(LAngleLoc, RAngleLoc), |
| 1345 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /// \brief Build a new C++ dynamic_cast expression. |
| 1349 | /// |
| 1350 | /// By default, performs semantic analysis to build the new expression. |
| 1351 | /// Subclasses may override this routine to provide different behavior. |
| 1352 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1353 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1354 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | SourceLocation RAngleLoc, |
| 1356 | SourceLocation LParenLoc, |
| 1357 | ExprArg SubExpr, |
| 1358 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1359 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1360 | TInfo, move(SubExpr), |
| 1361 | SourceRange(LAngleLoc, RAngleLoc), |
| 1362 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1366 | /// |
| 1367 | /// By default, performs semantic analysis to build the new expression. |
| 1368 | /// Subclasses may override this routine to provide different behavior. |
| 1369 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1370 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1371 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | SourceLocation RAngleLoc, |
| 1373 | SourceLocation LParenLoc, |
| 1374 | ExprArg SubExpr, |
| 1375 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1376 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1377 | TInfo, move(SubExpr), |
| 1378 | SourceRange(LAngleLoc, RAngleLoc), |
| 1379 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | /// \brief Build a new C++ const_cast expression. |
| 1383 | /// |
| 1384 | /// By default, performs semantic analysis to build the new expression. |
| 1385 | /// Subclasses may override this routine to provide different behavior. |
| 1386 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1387 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1388 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1389 | SourceLocation RAngleLoc, |
| 1390 | SourceLocation LParenLoc, |
| 1391 | ExprArg SubExpr, |
| 1392 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1393 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1394 | TInfo, move(SubExpr), |
| 1395 | SourceRange(LAngleLoc, RAngleLoc), |
| 1396 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// \brief Build a new C++ functional-style cast expression. |
| 1400 | /// |
| 1401 | /// By default, performs semantic analysis to build the new expression. |
| 1402 | /// Subclasses may override this routine to provide different behavior. |
| 1403 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1404 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | SourceLocation LParenLoc, |
| 1406 | ExprArg SubExpr, |
| 1407 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1408 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1409 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1410 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1411 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1412 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | RParenLoc); |
| 1415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | /// \brief Build a new C++ typeid(type) expression. |
| 1418 | /// |
| 1419 | /// By default, performs semantic analysis to build the new expression. |
| 1420 | /// Subclasses may override this routine to provide different behavior. |
| 1421 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1422 | SourceLocation LParenLoc, |
| 1423 | QualType T, |
| 1424 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | T.getAsOpaquePtr(), RParenLoc); |
| 1427 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | /// \brief Build a new C++ typeid(expr) expression. |
| 1430 | /// |
| 1431 | /// By default, performs semantic analysis to build the new expression. |
| 1432 | /// Subclasses may override this routine to provide different behavior. |
| 1433 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1434 | SourceLocation LParenLoc, |
| 1435 | ExprArg Operand, |
| 1436 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1439 | RParenLoc); |
| 1440 | if (Result.isInvalid()) |
| 1441 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1442 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1444 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | /// \brief Build a new C++ "this" expression. |
| 1448 | /// |
| 1449 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1452 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1453 | QualType ThisType, |
| 1454 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1456 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1457 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /// \brief Build a new C++ throw expression. |
| 1461 | /// |
| 1462 | /// By default, performs semantic analysis to build the new expression. |
| 1463 | /// Subclasses may override this routine to provide different behavior. |
| 1464 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1465 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1466 | } |
| 1467 | |
| 1468 | /// \brief Build a new C++ default-argument expression. |
| 1469 | /// |
| 1470 | /// By default, builds a new default-argument expression, which does not |
| 1471 | /// require any semantic analysis. Subclasses may override this routine to |
| 1472 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1473 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1474 | ParmVarDecl *Param) { |
| 1475 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1476 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /// \brief Build a new C++ zero-initialization expression. |
| 1480 | /// |
| 1481 | /// By default, performs semantic analysis to build the new expression. |
| 1482 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1483 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1484 | SourceLocation LParenLoc, |
| 1485 | QualType T, |
| 1486 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1487 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1488 | T.getAsOpaquePtr(), LParenLoc, |
| 1489 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1490 | 0, RParenLoc); |
| 1491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | /// \brief Build a new C++ "new" expression. |
| 1494 | /// |
| 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1497 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1498 | bool UseGlobal, |
| 1499 | SourceLocation PlacementLParen, |
| 1500 | MultiExprArg PlacementArgs, |
| 1501 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1502 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | QualType AllocType, |
| 1504 | SourceLocation TypeLoc, |
| 1505 | SourceRange TypeRange, |
| 1506 | ExprArg ArraySize, |
| 1507 | SourceLocation ConstructorLParen, |
| 1508 | MultiExprArg ConstructorArgs, |
| 1509 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1510 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | PlacementLParen, |
| 1512 | move(PlacementArgs), |
| 1513 | PlacementRParen, |
| 1514 | ParenTypeId, |
| 1515 | AllocType, |
| 1516 | TypeLoc, |
| 1517 | TypeRange, |
| 1518 | move(ArraySize), |
| 1519 | ConstructorLParen, |
| 1520 | move(ConstructorArgs), |
| 1521 | ConstructorRParen); |
| 1522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1524 | /// \brief Build a new C++ "delete" expression. |
| 1525 | /// |
| 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
| 1528 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1529 | bool IsGlobalDelete, |
| 1530 | bool IsArrayForm, |
| 1531 | ExprArg Operand) { |
| 1532 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1533 | move(Operand)); |
| 1534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1536 | /// \brief Build a new unary type trait expression. |
| 1537 | /// |
| 1538 | /// By default, performs semantic analysis to build the new expression. |
| 1539 | /// Subclasses may override this routine to provide different behavior. |
| 1540 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1541 | SourceLocation StartLoc, |
| 1542 | SourceLocation LParenLoc, |
| 1543 | QualType T, |
| 1544 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | T.getAsOpaquePtr(), RParenLoc); |
| 1547 | } |
| 1548 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1549 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1550 | /// expression. |
| 1551 | /// |
| 1552 | /// By default, performs semantic analysis to build the new expression. |
| 1553 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1554 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | SourceRange QualifierRange, |
| 1556 | DeclarationName Name, |
| 1557 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1558 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | CXXScopeSpec SS; |
| 1560 | SS.setRange(QualifierRange); |
| 1561 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1562 | |
| 1563 | if (TemplateArgs) |
| 1564 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1565 | *TemplateArgs); |
| 1566 | |
| 1567 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | /// \brief Build a new template-id expression. |
| 1571 | /// |
| 1572 | /// By default, performs semantic analysis to build the new expression. |
| 1573 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1574 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1575 | LookupResult &R, |
| 1576 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1577 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1578 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /// \brief Build a new object-construction expression. |
| 1582 | /// |
| 1583 | /// By default, performs semantic analysis to build the new expression. |
| 1584 | /// Subclasses may override this routine to provide different behavior. |
| 1585 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1586 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | CXXConstructorDecl *Constructor, |
| 1588 | bool IsElidable, |
| 1589 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1590 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1591 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1592 | ConvertedArgs)) |
| 1593 | return getSema().ExprError(); |
| 1594 | |
| 1595 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1596 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /// \brief Build a new object-construction expression. |
| 1600 | /// |
| 1601 | /// By default, performs semantic analysis to build the new expression. |
| 1602 | /// Subclasses may override this routine to provide different behavior. |
| 1603 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1604 | QualType T, |
| 1605 | SourceLocation LParenLoc, |
| 1606 | MultiExprArg Args, |
| 1607 | SourceLocation *Commas, |
| 1608 | SourceLocation RParenLoc) { |
| 1609 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1610 | T.getAsOpaquePtr(), |
| 1611 | LParenLoc, |
| 1612 | move(Args), |
| 1613 | Commas, |
| 1614 | RParenLoc); |
| 1615 | } |
| 1616 | |
| 1617 | /// \brief Build a new object-construction expression. |
| 1618 | /// |
| 1619 | /// By default, performs semantic analysis to build the new expression. |
| 1620 | /// Subclasses may override this routine to provide different behavior. |
| 1621 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1622 | QualType T, |
| 1623 | SourceLocation LParenLoc, |
| 1624 | MultiExprArg Args, |
| 1625 | SourceLocation *Commas, |
| 1626 | SourceLocation RParenLoc) { |
| 1627 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1628 | /*FIXME*/LParenLoc), |
| 1629 | T.getAsOpaquePtr(), |
| 1630 | LParenLoc, |
| 1631 | move(Args), |
| 1632 | Commas, |
| 1633 | RParenLoc); |
| 1634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | /// \brief Build a new member reference expression. |
| 1637 | /// |
| 1638 | /// By default, performs semantic analysis to build the new expression. |
| 1639 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1640 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1641 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1642 | bool IsArrow, |
| 1643 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1644 | NestedNameSpecifier *Qualifier, |
| 1645 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1646 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1648 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1649 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1651 | SS.setRange(QualifierRange); |
| 1652 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1654 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1655 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1656 | SS, FirstQualifierInScope, |
| 1657 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1660 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1661 | /// |
| 1662 | /// By default, performs semantic analysis to build the new expression. |
| 1663 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1664 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1665 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1666 | SourceLocation OperatorLoc, |
| 1667 | bool IsArrow, |
| 1668 | NestedNameSpecifier *Qualifier, |
| 1669 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1670 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1671 | LookupResult &R, |
| 1672 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1673 | CXXScopeSpec SS; |
| 1674 | SS.setRange(QualifierRange); |
| 1675 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1677 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1678 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1679 | SS, FirstQualifierInScope, |
| 1680 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | /// \brief Build a new Objective-C @encode expression. |
| 1684 | /// |
| 1685 | /// By default, performs semantic analysis to build the new expression. |
| 1686 | /// Subclasses may override this routine to provide different behavior. |
| 1687 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1688 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1690 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1691 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1692 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1694 | /// \brief Build a new Objective-C class message. |
| 1695 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1696 | Selector Sel, |
| 1697 | ObjCMethodDecl *Method, |
| 1698 | SourceLocation LBracLoc, |
| 1699 | MultiExprArg Args, |
| 1700 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1701 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1702 | ReceiverTypeInfo->getType(), |
| 1703 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1704 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1705 | move(Args)); |
| 1706 | } |
| 1707 | |
| 1708 | /// \brief Build a new Objective-C instance message. |
| 1709 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1710 | Selector Sel, |
| 1711 | ObjCMethodDecl *Method, |
| 1712 | SourceLocation LBracLoc, |
| 1713 | MultiExprArg Args, |
| 1714 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1715 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1716 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1717 | ReceiverType, |
| 1718 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1719 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1720 | move(Args)); |
| 1721 | } |
| 1722 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | /// \brief Build a new Objective-C protocol expression. |
| 1724 | /// |
| 1725 | /// By default, performs semantic analysis to build the new expression. |
| 1726 | /// Subclasses may override this routine to provide different behavior. |
| 1727 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1728 | SourceLocation AtLoc, |
| 1729 | SourceLocation ProtoLoc, |
| 1730 | SourceLocation LParenLoc, |
| 1731 | SourceLocation RParenLoc) { |
| 1732 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1733 | Protocol->getIdentifier(), |
| 1734 | AtLoc, |
| 1735 | ProtoLoc, |
| 1736 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1738 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1739 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1740 | /// \brief Build a new shuffle vector expression. |
| 1741 | /// |
| 1742 | /// By default, performs semantic analysis to build the new expression. |
| 1743 | /// Subclasses may override this routine to provide different behavior. |
| 1744 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1745 | MultiExprArg SubExprs, |
| 1746 | SourceLocation RParenLoc) { |
| 1747 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1749 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1750 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1751 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1752 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1753 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1754 | // Build a reference to the __builtin_shufflevector builtin |
| 1755 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1757 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1758 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
| 1761 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1762 | unsigned NumSubExprs = SubExprs.size(); |
| 1763 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1764 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1765 | Subs, NumSubExprs, |
| 1766 | Builtin->getResultType(), |
| 1767 | RParenLoc); |
| 1768 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1770 | // Type-check the __builtin_shufflevector expression. |
| 1771 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1772 | if (Result.isInvalid()) |
| 1773 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1775 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1777 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1778 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1779 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1780 | template<typename Derived> |
| 1781 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1782 | if (!S) |
| 1783 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1785 | switch (S->getStmtClass()) { |
| 1786 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1787 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1788 | // Transform individual statement nodes |
| 1789 | #define STMT(Node, Parent) \ |
| 1790 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1791 | #define EXPR(Node, Parent) |
| 1792 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1794 | // Transform expressions by calling TransformExpr. |
| 1795 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1796 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1797 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1798 | #include "clang/AST/StmtNodes.def" |
| 1799 | { |
| 1800 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1801 | if (E.isInvalid()) |
| 1802 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1804 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1808 | return SemaRef.Owned(S->Retain()); |
| 1809 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | |
| 1811 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1812 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1813 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1814 | if (!E) |
| 1815 | return SemaRef.Owned(E); |
| 1816 | |
| 1817 | switch (E->getStmtClass()) { |
| 1818 | case Stmt::NoStmtClass: break; |
| 1819 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1820 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1821 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1822 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1823 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1826 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1830 | NestedNameSpecifier * |
| 1831 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1832 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1833 | QualType ObjectType, |
| 1834 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1835 | if (!NNS) |
| 1836 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1838 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1839 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1840 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1842 | ObjectType, |
| 1843 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1844 | if (!Prefix) |
| 1845 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1846 | |
| 1847 | // 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] | 1848 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1849 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1850 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1853 | switch (NNS->getKind()) { |
| 1854 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1856 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1857 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1858 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1859 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | |
| 1861 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1862 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1863 | ObjectType, |
| 1864 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1866 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1868 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1869 | getDerived().TransformDecl(Range.getBegin(), |
| 1870 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1872 | Prefix == NNS->getPrefix() && |
| 1873 | NS == NNS->getAsNamespace()) |
| 1874 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1876 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1877 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1878 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1879 | case NestedNameSpecifier::Global: |
| 1880 | // There is no meaningful transformation that one could perform on the |
| 1881 | // global scope. |
| 1882 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1883 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1884 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1885 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1886 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1887 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1888 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1889 | if (T.isNull()) |
| 1890 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1892 | if (!getDerived().AlwaysRebuild() && |
| 1893 | Prefix == NNS->getPrefix() && |
| 1894 | T == QualType(NNS->getAsType(), 0)) |
| 1895 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1896 | |
| 1897 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1898 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 1899 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1900 | } |
| 1901 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1902 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1903 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1904 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1909 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1910 | SourceLocation Loc, |
| 1911 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1912 | if (!Name) |
| 1913 | return Name; |
| 1914 | |
| 1915 | switch (Name.getNameKind()) { |
| 1916 | case DeclarationName::Identifier: |
| 1917 | case DeclarationName::ObjCZeroArgSelector: |
| 1918 | case DeclarationName::ObjCOneArgSelector: |
| 1919 | case DeclarationName::ObjCMultiArgSelector: |
| 1920 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1921 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1922 | case DeclarationName::CXXUsingDirective: |
| 1923 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1925 | case DeclarationName::CXXConstructorName: |
| 1926 | case DeclarationName::CXXDestructorName: |
| 1927 | case DeclarationName::CXXConversionFunctionName: { |
| 1928 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1929 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1930 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1931 | if (T.isNull()) |
| 1932 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1933 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1934 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1935 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1936 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1937 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1940 | return DeclarationName(); |
| 1941 | } |
| 1942 | |
| 1943 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1944 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1945 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1946 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1947 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1948 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1949 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1950 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1951 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1952 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1953 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1954 | if (!NNS) |
| 1955 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1956 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1957 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1959 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1960 | if (!TransTemplate) |
| 1961 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1963 | if (!getDerived().AlwaysRebuild() && |
| 1964 | NNS == QTN->getQualifier() && |
| 1965 | TransTemplate == Template) |
| 1966 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1967 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1968 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1969 | TransTemplate); |
| 1970 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1971 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1972 | // These should be getting filtered out before they make it into the AST. |
| 1973 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1974 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1975 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1976 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1978 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1979 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1980 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1981 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1982 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1983 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1984 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1985 | NNS == DTN->getQualifier() && |
| 1986 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1987 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1988 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1989 | if (DTN->isIdentifier()) |
| 1990 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1991 | ObjectType); |
| 1992 | |
| 1993 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1994 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1997 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1998 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 1999 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2000 | if (!TransTemplate) |
| 2001 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2002 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2003 | if (!getDerived().AlwaysRebuild() && |
| 2004 | TransTemplate == Template) |
| 2005 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2006 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2007 | return TemplateName(TransTemplate); |
| 2008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2010 | // These should be getting filtered out before they reach the AST. |
| 2011 | assert(false && "overloaded function decl survived to here"); |
| 2012 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2016 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2017 | const TemplateArgument &Arg, |
| 2018 | TemplateArgumentLoc &Output) { |
| 2019 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2020 | switch (Arg.getKind()) { |
| 2021 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2022 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2023 | break; |
| 2024 | |
| 2025 | case TemplateArgument::Type: |
| 2026 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2027 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2028 | |
| 2029 | break; |
| 2030 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2031 | case TemplateArgument::Template: |
| 2032 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2033 | break; |
| 2034 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2035 | case TemplateArgument::Expression: |
| 2036 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2037 | break; |
| 2038 | |
| 2039 | case TemplateArgument::Declaration: |
| 2040 | case TemplateArgument::Integral: |
| 2041 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2042 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | template<typename Derived> |
| 2048 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2049 | const TemplateArgumentLoc &Input, |
| 2050 | TemplateArgumentLoc &Output) { |
| 2051 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2052 | switch (Arg.getKind()) { |
| 2053 | case TemplateArgument::Null: |
| 2054 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2055 | Output = Input; |
| 2056 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2057 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2058 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2059 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2060 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2061 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2062 | |
| 2063 | DI = getDerived().TransformType(DI); |
| 2064 | if (!DI) return true; |
| 2065 | |
| 2066 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2067 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2070 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2071 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2072 | DeclarationName Name; |
| 2073 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2074 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2075 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2076 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2077 | if (!D) return true; |
| 2078 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2079 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2080 | if (SourceExpr) { |
| 2081 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2082 | Action::Unevaluated); |
| 2083 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2084 | if (E.isInvalid()) |
| 2085 | SourceExpr = NULL; |
| 2086 | else { |
| 2087 | SourceExpr = E.takeAs<Expr>(); |
| 2088 | SourceExpr->Retain(); |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2093 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2095 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2096 | case TemplateArgument::Template: { |
| 2097 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2098 | TemplateName Template |
| 2099 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2100 | if (Template.isNull()) |
| 2101 | return true; |
| 2102 | |
| 2103 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2104 | Input.getTemplateQualifierRange(), |
| 2105 | Input.getTemplateNameLoc()); |
| 2106 | return false; |
| 2107 | } |
| 2108 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2109 | case TemplateArgument::Expression: { |
| 2110 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2111 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2112 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2113 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2114 | Expr *InputExpr = Input.getSourceExpression(); |
| 2115 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2116 | |
| 2117 | Sema::OwningExprResult E |
| 2118 | = getDerived().TransformExpr(InputExpr); |
| 2119 | if (E.isInvalid()) return true; |
| 2120 | |
| 2121 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2122 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2123 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2124 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2127 | case TemplateArgument::Pack: { |
| 2128 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2129 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2130 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2131 | AEnd = Arg.pack_end(); |
| 2132 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2133 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2134 | // FIXME: preserve source information here when we start |
| 2135 | // caring about parameter packs. |
| 2136 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2137 | TemplateArgumentLoc InputArg; |
| 2138 | TemplateArgumentLoc OutputArg; |
| 2139 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2140 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2141 | return true; |
| 2142 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2143 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2144 | } |
| 2145 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2146 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2147 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2148 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2149 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2150 | } |
| 2151 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2152 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2153 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2154 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2157 | //===----------------------------------------------------------------------===// |
| 2158 | // Type transformation |
| 2159 | //===----------------------------------------------------------------------===// |
| 2160 | |
| 2161 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2162 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2163 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2164 | if (getDerived().AlreadyTransformed(T)) |
| 2165 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2166 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2167 | // Temporary workaround. All of these transformations should |
| 2168 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2169 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2170 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2172 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2173 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2174 | if (!NewDI) |
| 2175 | return QualType(); |
| 2176 | |
| 2177 | return NewDI->getType(); |
| 2178 | } |
| 2179 | |
| 2180 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2181 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2182 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2183 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2184 | return DI; |
| 2185 | |
| 2186 | TypeLocBuilder TLB; |
| 2187 | |
| 2188 | TypeLoc TL = DI->getTypeLoc(); |
| 2189 | TLB.reserve(TL.getFullDataSize()); |
| 2190 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2191 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2192 | if (Result.isNull()) |
| 2193 | return 0; |
| 2194 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2195 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | template<typename Derived> |
| 2199 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2200 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2201 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2202 | switch (T.getTypeLocClass()) { |
| 2203 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2204 | #define TYPELOC(CLASS, PARENT) \ |
| 2205 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2206 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2207 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2208 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2209 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2211 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2212 | return QualType(); |
| 2213 | } |
| 2214 | |
| 2215 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2216 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2217 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2218 | /// types). This is the right thing for template instantiation, but |
| 2219 | /// probably not for other clients. |
| 2220 | template<typename Derived> |
| 2221 | QualType |
| 2222 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2223 | QualifiedTypeLoc T, |
| 2224 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2225 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2226 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2227 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2228 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2229 | if (Result.isNull()) |
| 2230 | return QualType(); |
| 2231 | |
| 2232 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2233 | // FIXME: this is the right thing for template instantiation, but |
| 2234 | // probably not for other clients. |
| 2235 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2236 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2237 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2238 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2239 | |
| 2240 | TLB.push<QualifiedTypeLoc>(Result); |
| 2241 | |
| 2242 | // No location information to preserve. |
| 2243 | |
| 2244 | return Result; |
| 2245 | } |
| 2246 | |
| 2247 | template <class TyLoc> static inline |
| 2248 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2249 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2250 | NewT.setNameLoc(T.getNameLoc()); |
| 2251 | return T.getType(); |
| 2252 | } |
| 2253 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2254 | template<typename Derived> |
| 2255 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2256 | BuiltinTypeLoc T, |
| 2257 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2258 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2259 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2260 | if (T.needsExtraLocalData()) |
| 2261 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2262 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2265 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2266 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2267 | ComplexTypeLoc T, |
| 2268 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2269 | // FIXME: recurse? |
| 2270 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2271 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2272 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2273 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2274 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2275 | PointerTypeLoc TL, |
| 2276 | QualType ObjectType) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2277 | QualType PointeeType |
| 2278 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2279 | if (PointeeType.isNull()) |
| 2280 | return QualType(); |
| 2281 | |
| 2282 | QualType Result = TL.getType(); |
| 2283 | if (PointeeType->isObjCInterfaceType()) { |
| 2284 | // A dependent pointer type 'T *' has is being transformed such |
| 2285 | // that an Objective-C class type is being replaced for 'T'. The |
| 2286 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2287 | // PointerType. |
| 2288 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2289 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2290 | const_cast<ObjCProtocolDecl **>( |
| 2291 | IFace->qual_begin()), |
| 2292 | IFace->getNumProtocols()); |
| 2293 | |
| 2294 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2295 | NewT.setStarLoc(TL.getSigilLoc()); |
| 2296 | NewT.setHasProtocolsAsWritten(false); |
| 2297 | NewT.setLAngleLoc(SourceLocation()); |
| 2298 | NewT.setRAngleLoc(SourceLocation()); |
| 2299 | NewT.setHasBaseTypeAsWritten(true); |
| 2300 | return Result; |
| 2301 | } |
| 2302 | |
| 2303 | if (getDerived().AlwaysRebuild() || |
| 2304 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2305 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2306 | if (Result.isNull()) |
| 2307 | return QualType(); |
| 2308 | } |
| 2309 | |
| 2310 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2311 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2312 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2313 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2314 | |
| 2315 | template<typename Derived> |
| 2316 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2317 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2318 | BlockPointerTypeLoc TL, |
| 2319 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2320 | QualType PointeeType |
| 2321 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2322 | if (PointeeType.isNull()) |
| 2323 | return QualType(); |
| 2324 | |
| 2325 | QualType Result = TL.getType(); |
| 2326 | if (getDerived().AlwaysRebuild() || |
| 2327 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2328 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 2329 | TL.getSigilLoc()); |
| 2330 | if (Result.isNull()) |
| 2331 | return QualType(); |
| 2332 | } |
| 2333 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2334 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2335 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2336 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2339 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2340 | /// don't care whether the type itself is an l-value type or an r-value |
| 2341 | /// type; we only care if the type was *written* as an l-value type |
| 2342 | /// or an r-value type. |
| 2343 | template<typename Derived> |
| 2344 | QualType |
| 2345 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2346 | ReferenceTypeLoc TL, |
| 2347 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2348 | const ReferenceType *T = TL.getTypePtr(); |
| 2349 | |
| 2350 | // Note that this works with the pointee-as-written. |
| 2351 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2352 | if (PointeeType.isNull()) |
| 2353 | return QualType(); |
| 2354 | |
| 2355 | QualType Result = TL.getType(); |
| 2356 | if (getDerived().AlwaysRebuild() || |
| 2357 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2358 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2359 | T->isSpelledAsLValue(), |
| 2360 | TL.getSigilLoc()); |
| 2361 | if (Result.isNull()) |
| 2362 | return QualType(); |
| 2363 | } |
| 2364 | |
| 2365 | // r-value references can be rebuilt as l-value references. |
| 2366 | ReferenceTypeLoc NewTL; |
| 2367 | if (isa<LValueReferenceType>(Result)) |
| 2368 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2369 | else |
| 2370 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2371 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2372 | |
| 2373 | return Result; |
| 2374 | } |
| 2375 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2376 | template<typename Derived> |
| 2377 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2378 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2379 | LValueReferenceTypeLoc TL, |
| 2380 | QualType ObjectType) { |
| 2381 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2384 | template<typename Derived> |
| 2385 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2386 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2387 | RValueReferenceTypeLoc TL, |
| 2388 | QualType ObjectType) { |
| 2389 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2390 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2391 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2392 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2393 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2394 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2395 | MemberPointerTypeLoc TL, |
| 2396 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2397 | MemberPointerType *T = TL.getTypePtr(); |
| 2398 | |
| 2399 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2400 | if (PointeeType.isNull()) |
| 2401 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2402 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2403 | // TODO: preserve source information for this. |
| 2404 | QualType ClassType |
| 2405 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2406 | if (ClassType.isNull()) |
| 2407 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2408 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2409 | QualType Result = TL.getType(); |
| 2410 | if (getDerived().AlwaysRebuild() || |
| 2411 | PointeeType != T->getPointeeType() || |
| 2412 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2413 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2414 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2415 | if (Result.isNull()) |
| 2416 | return QualType(); |
| 2417 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2418 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2419 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2420 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2421 | |
| 2422 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2425 | template<typename Derived> |
| 2426 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2427 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2428 | ConstantArrayTypeLoc TL, |
| 2429 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2430 | ConstantArrayType *T = TL.getTypePtr(); |
| 2431 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2432 | if (ElementType.isNull()) |
| 2433 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2434 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2435 | QualType Result = TL.getType(); |
| 2436 | if (getDerived().AlwaysRebuild() || |
| 2437 | ElementType != T->getElementType()) { |
| 2438 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2439 | T->getSizeModifier(), |
| 2440 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2441 | T->getIndexTypeCVRQualifiers(), |
| 2442 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2443 | if (Result.isNull()) |
| 2444 | return QualType(); |
| 2445 | } |
| 2446 | |
| 2447 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2448 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2449 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2450 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2451 | Expr *Size = TL.getSizeExpr(); |
| 2452 | if (Size) { |
| 2453 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2454 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2455 | } |
| 2456 | NewTL.setSizeExpr(Size); |
| 2457 | |
| 2458 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2459 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2460 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2461 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2462 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2464 | IncompleteArrayTypeLoc TL, |
| 2465 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2466 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2467 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2468 | if (ElementType.isNull()) |
| 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() || |
| 2473 | ElementType != T->getElementType()) { |
| 2474 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2475 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2476 | T->getIndexTypeCVRQualifiers(), |
| 2477 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2478 | if (Result.isNull()) |
| 2479 | return QualType(); |
| 2480 | } |
| 2481 | |
| 2482 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2483 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2484 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2485 | NewTL.setSizeExpr(0); |
| 2486 | |
| 2487 | return Result; |
| 2488 | } |
| 2489 | |
| 2490 | template<typename Derived> |
| 2491 | QualType |
| 2492 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2493 | VariableArrayTypeLoc TL, |
| 2494 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2495 | VariableArrayType *T = TL.getTypePtr(); |
| 2496 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2497 | if (ElementType.isNull()) |
| 2498 | return QualType(); |
| 2499 | |
| 2500 | // Array bounds are not potentially evaluated contexts |
| 2501 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2502 | |
| 2503 | Sema::OwningExprResult SizeResult |
| 2504 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2505 | if (SizeResult.isInvalid()) |
| 2506 | return QualType(); |
| 2507 | |
| 2508 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2509 | |
| 2510 | QualType Result = TL.getType(); |
| 2511 | if (getDerived().AlwaysRebuild() || |
| 2512 | ElementType != T->getElementType() || |
| 2513 | Size != T->getSizeExpr()) { |
| 2514 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2515 | T->getSizeModifier(), |
| 2516 | move(SizeResult), |
| 2517 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2518 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2519 | if (Result.isNull()) |
| 2520 | return QualType(); |
| 2521 | } |
| 2522 | else SizeResult.take(); |
| 2523 | |
| 2524 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2525 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2526 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2527 | NewTL.setSizeExpr(Size); |
| 2528 | |
| 2529 | return Result; |
| 2530 | } |
| 2531 | |
| 2532 | template<typename Derived> |
| 2533 | QualType |
| 2534 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2535 | DependentSizedArrayTypeLoc TL, |
| 2536 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2537 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2538 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2539 | if (ElementType.isNull()) |
| 2540 | return QualType(); |
| 2541 | |
| 2542 | // Array bounds are not potentially evaluated contexts |
| 2543 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2544 | |
| 2545 | Sema::OwningExprResult SizeResult |
| 2546 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2547 | if (SizeResult.isInvalid()) |
| 2548 | return QualType(); |
| 2549 | |
| 2550 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2551 | |
| 2552 | QualType Result = TL.getType(); |
| 2553 | if (getDerived().AlwaysRebuild() || |
| 2554 | ElementType != T->getElementType() || |
| 2555 | Size != T->getSizeExpr()) { |
| 2556 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2557 | T->getSizeModifier(), |
| 2558 | move(SizeResult), |
| 2559 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2560 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2561 | if (Result.isNull()) |
| 2562 | return QualType(); |
| 2563 | } |
| 2564 | else SizeResult.take(); |
| 2565 | |
| 2566 | // We might have any sort of array type now, but fortunately they |
| 2567 | // all have the same location layout. |
| 2568 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2569 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2570 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2571 | NewTL.setSizeExpr(Size); |
| 2572 | |
| 2573 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2574 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2575 | |
| 2576 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2577 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2578 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2579 | DependentSizedExtVectorTypeLoc TL, |
| 2580 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2581 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2582 | |
| 2583 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2584 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2585 | if (ElementType.isNull()) |
| 2586 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2588 | // Vector sizes are not potentially evaluated contexts |
| 2589 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2590 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2591 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2592 | if (Size.isInvalid()) |
| 2593 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2594 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2595 | QualType Result = TL.getType(); |
| 2596 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2597 | ElementType != T->getElementType() || |
| 2598 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2599 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2600 | move(Size), |
| 2601 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2602 | if (Result.isNull()) |
| 2603 | return QualType(); |
| 2604 | } |
| 2605 | else Size.take(); |
| 2606 | |
| 2607 | // Result might be dependent or not. |
| 2608 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2609 | DependentSizedExtVectorTypeLoc NewTL |
| 2610 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2611 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2612 | } else { |
| 2613 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2614 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2615 | } |
| 2616 | |
| 2617 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2618 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 | |
| 2620 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2621 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2622 | VectorTypeLoc TL, |
| 2623 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2624 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2626 | if (ElementType.isNull()) |
| 2627 | return QualType(); |
| 2628 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2629 | QualType Result = TL.getType(); |
| 2630 | if (getDerived().AlwaysRebuild() || |
| 2631 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2632 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2633 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2634 | if (Result.isNull()) |
| 2635 | return QualType(); |
| 2636 | } |
| 2637 | |
| 2638 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2639 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2640 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2641 | return Result; |
| 2642 | } |
| 2643 | |
| 2644 | template<typename Derived> |
| 2645 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2646 | ExtVectorTypeLoc TL, |
| 2647 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2648 | VectorType *T = TL.getTypePtr(); |
| 2649 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2650 | if (ElementType.isNull()) |
| 2651 | return QualType(); |
| 2652 | |
| 2653 | QualType Result = TL.getType(); |
| 2654 | if (getDerived().AlwaysRebuild() || |
| 2655 | ElementType != T->getElementType()) { |
| 2656 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2657 | T->getNumElements(), |
| 2658 | /*FIXME*/ SourceLocation()); |
| 2659 | if (Result.isNull()) |
| 2660 | return QualType(); |
| 2661 | } |
| 2662 | |
| 2663 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2664 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2665 | |
| 2666 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2668 | |
| 2669 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2670 | ParmVarDecl * |
| 2671 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2672 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2673 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2674 | if (!NewDI) |
| 2675 | return 0; |
| 2676 | |
| 2677 | if (NewDI == OldDI) |
| 2678 | return OldParm; |
| 2679 | else |
| 2680 | return ParmVarDecl::Create(SemaRef.Context, |
| 2681 | OldParm->getDeclContext(), |
| 2682 | OldParm->getLocation(), |
| 2683 | OldParm->getIdentifier(), |
| 2684 | NewDI->getType(), |
| 2685 | NewDI, |
| 2686 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2687 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2688 | /* DefArg */ NULL); |
| 2689 | } |
| 2690 | |
| 2691 | template<typename Derived> |
| 2692 | bool TreeTransform<Derived>:: |
| 2693 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2694 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2695 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2696 | FunctionProtoType *T = TL.getTypePtr(); |
| 2697 | |
| 2698 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2699 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2700 | |
| 2701 | QualType NewType; |
| 2702 | ParmVarDecl *NewParm; |
| 2703 | |
| 2704 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2705 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2706 | if (!NewParm) |
| 2707 | return true; |
| 2708 | NewType = NewParm->getType(); |
| 2709 | |
| 2710 | // Deal with the possibility that we don't have a parameter |
| 2711 | // declaration for this parameter. |
| 2712 | } else { |
| 2713 | NewParm = 0; |
| 2714 | |
| 2715 | QualType OldType = T->getArgType(i); |
| 2716 | NewType = getDerived().TransformType(OldType); |
| 2717 | if (NewType.isNull()) |
| 2718 | return true; |
| 2719 | } |
| 2720 | |
| 2721 | PTypes.push_back(NewType); |
| 2722 | PVars.push_back(NewParm); |
| 2723 | } |
| 2724 | |
| 2725 | return false; |
| 2726 | } |
| 2727 | |
| 2728 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2729 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2730 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2731 | FunctionProtoTypeLoc TL, |
| 2732 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2733 | FunctionProtoType *T = TL.getTypePtr(); |
| 2734 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2735 | if (ResultType.isNull()) |
| 2736 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2737 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2738 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2739 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2740 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2741 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2742 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2743 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2744 | QualType Result = TL.getType(); |
| 2745 | if (getDerived().AlwaysRebuild() || |
| 2746 | ResultType != T->getResultType() || |
| 2747 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2748 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2749 | ParamTypes.data(), |
| 2750 | ParamTypes.size(), |
| 2751 | T->isVariadic(), |
| 2752 | T->getTypeQuals()); |
| 2753 | if (Result.isNull()) |
| 2754 | return QualType(); |
| 2755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2756 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2757 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2758 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2759 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2760 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2761 | NewTL.setArg(i, ParamDecls[i]); |
| 2762 | |
| 2763 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2764 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2766 | template<typename Derived> |
| 2767 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2768 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2769 | FunctionNoProtoTypeLoc TL, |
| 2770 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2772 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2773 | if (ResultType.isNull()) |
| 2774 | return QualType(); |
| 2775 | |
| 2776 | QualType Result = TL.getType(); |
| 2777 | if (getDerived().AlwaysRebuild() || |
| 2778 | ResultType != T->getResultType()) |
| 2779 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2780 | |
| 2781 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2782 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2783 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2784 | |
| 2785 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2786 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2787 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2788 | template<typename Derived> QualType |
| 2789 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2790 | UnresolvedUsingTypeLoc TL, |
| 2791 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2792 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2793 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2794 | if (!D) |
| 2795 | return QualType(); |
| 2796 | |
| 2797 | QualType Result = TL.getType(); |
| 2798 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2799 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2800 | if (Result.isNull()) |
| 2801 | return QualType(); |
| 2802 | } |
| 2803 | |
| 2804 | // We might get an arbitrary type spec type back. We should at |
| 2805 | // least always get a type spec type, though. |
| 2806 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2807 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2808 | |
| 2809 | return Result; |
| 2810 | } |
| 2811 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2812 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2813 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2814 | TypedefTypeLoc TL, |
| 2815 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2816 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2817 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2818 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2819 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | if (!Typedef) |
| 2821 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2822 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2823 | QualType Result = TL.getType(); |
| 2824 | if (getDerived().AlwaysRebuild() || |
| 2825 | Typedef != T->getDecl()) { |
| 2826 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2827 | if (Result.isNull()) |
| 2828 | return QualType(); |
| 2829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2830 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2831 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2832 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2833 | |
| 2834 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2836 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2837 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2838 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2839 | TypeOfExprTypeLoc TL, |
| 2840 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2841 | // typeof expressions are not potentially evaluated contexts |
| 2842 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2843 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2844 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2845 | if (E.isInvalid()) |
| 2846 | return QualType(); |
| 2847 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2848 | QualType Result = TL.getType(); |
| 2849 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2850 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2851 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2852 | if (Result.isNull()) |
| 2853 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2854 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2855 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2857 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2858 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2859 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2860 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2861 | |
| 2862 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2863 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2864 | |
| 2865 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2866 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2867 | TypeOfTypeLoc TL, |
| 2868 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2869 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2870 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2871 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2872 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2873 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2874 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2875 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2876 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2877 | if (Result.isNull()) |
| 2878 | return QualType(); |
| 2879 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2880 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2881 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2882 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2883 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2884 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2885 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2886 | |
| 2887 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2888 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2889 | |
| 2890 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2891 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2892 | DecltypeTypeLoc TL, |
| 2893 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2894 | DecltypeType *T = TL.getTypePtr(); |
| 2895 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2896 | // decltype expressions are not potentially evaluated contexts |
| 2897 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2898 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2899 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2900 | if (E.isInvalid()) |
| 2901 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2902 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2903 | QualType Result = TL.getType(); |
| 2904 | if (getDerived().AlwaysRebuild() || |
| 2905 | E.get() != T->getUnderlyingExpr()) { |
| 2906 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2907 | if (Result.isNull()) |
| 2908 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2910 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2911 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2912 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2913 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2914 | |
| 2915 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2919 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2920 | RecordTypeLoc TL, |
| 2921 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2922 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2923 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2924 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2925 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2926 | if (!Record) |
| 2927 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2928 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2929 | QualType Result = TL.getType(); |
| 2930 | if (getDerived().AlwaysRebuild() || |
| 2931 | Record != T->getDecl()) { |
| 2932 | Result = getDerived().RebuildRecordType(Record); |
| 2933 | if (Result.isNull()) |
| 2934 | return QualType(); |
| 2935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2936 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2937 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2938 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2939 | |
| 2940 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2941 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2942 | |
| 2943 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2944 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2945 | EnumTypeLoc TL, |
| 2946 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2947 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2948 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2949 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2950 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2951 | if (!Enum) |
| 2952 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2954 | QualType Result = TL.getType(); |
| 2955 | if (getDerived().AlwaysRebuild() || |
| 2956 | Enum != T->getDecl()) { |
| 2957 | Result = getDerived().RebuildEnumType(Enum); |
| 2958 | if (Result.isNull()) |
| 2959 | return QualType(); |
| 2960 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2962 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2963 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2964 | |
| 2965 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2966 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2967 | |
| 2968 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2969 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2970 | ElaboratedTypeLoc TL, |
| 2971 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2972 | ElaboratedType *T = TL.getTypePtr(); |
| 2973 | |
| 2974 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2975 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2976 | if (Underlying.isNull()) |
| 2977 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2978 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2979 | QualType Result = TL.getType(); |
| 2980 | if (getDerived().AlwaysRebuild() || |
| 2981 | Underlying != T->getUnderlyingType()) { |
| 2982 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2983 | if (Result.isNull()) |
| 2984 | return QualType(); |
| 2985 | } |
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 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2988 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2989 | |
| 2990 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2993 | template<typename Derived> |
| 2994 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 2995 | TypeLocBuilder &TLB, |
| 2996 | InjectedClassNameTypeLoc TL, |
| 2997 | QualType ObjectType) { |
| 2998 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 2999 | TL.getTypePtr()->getDecl()); |
| 3000 | if (!D) return QualType(); |
| 3001 | |
| 3002 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3003 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3004 | return T; |
| 3005 | } |
| 3006 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3007 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3008 | template<typename Derived> |
| 3009 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3010 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3011 | TemplateTypeParmTypeLoc TL, |
| 3012 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3013 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3016 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3017 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3018 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3019 | SubstTemplateTypeParmTypeLoc TL, |
| 3020 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3021 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3025 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3026 | const TemplateSpecializationType *TST, |
| 3027 | QualType ObjectType) { |
| 3028 | // FIXME: this entire method is a temporary workaround; callers |
| 3029 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3030 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3031 | // Fake up a TemplateSpecializationTypeLoc. |
| 3032 | TypeLocBuilder TLB; |
| 3033 | TemplateSpecializationTypeLoc TL |
| 3034 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3035 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3036 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3037 | |
| 3038 | TL.setTemplateNameLoc(BaseLoc); |
| 3039 | TL.setLAngleLoc(BaseLoc); |
| 3040 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3041 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3042 | const TemplateArgument &TA = TST->getArg(i); |
| 3043 | TemplateArgumentLoc TAL; |
| 3044 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3045 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3046 | } |
| 3047 | |
| 3048 | TypeLocBuilder IgnoredTLB; |
| 3049 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3053 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3054 | TypeLocBuilder &TLB, |
| 3055 | TemplateSpecializationTypeLoc TL, |
| 3056 | QualType ObjectType) { |
| 3057 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3058 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3059 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3060 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3061 | if (Template.isNull()) |
| 3062 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3063 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3064 | TemplateArgumentListInfo NewTemplateArgs; |
| 3065 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3066 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3067 | |
| 3068 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3069 | TemplateArgumentLoc Loc; |
| 3070 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3071 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3072 | NewTemplateArgs.addArgument(Loc); |
| 3073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3074 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3075 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3076 | |
| 3077 | QualType Result = |
| 3078 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3079 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3080 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3081 | |
| 3082 | if (!Result.isNull()) { |
| 3083 | TemplateSpecializationTypeLoc NewTL |
| 3084 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3085 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3086 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3087 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3088 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3089 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3090 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3091 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3092 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
| 3095 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3096 | QualType |
| 3097 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3098 | QualifiedNameTypeLoc TL, |
| 3099 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3100 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3101 | NestedNameSpecifier *NNS |
| 3102 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3103 | SourceRange(), |
| 3104 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3105 | if (!NNS) |
| 3106 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3107 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3108 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3109 | if (Named.isNull()) |
| 3110 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3112 | QualType Result = TL.getType(); |
| 3113 | if (getDerived().AlwaysRebuild() || |
| 3114 | NNS != T->getQualifier() || |
| 3115 | Named != T->getNamedType()) { |
| 3116 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3117 | if (Result.isNull()) |
| 3118 | return QualType(); |
| 3119 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3120 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3121 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3122 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3123 | |
| 3124 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3126 | |
| 3127 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3128 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3129 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3130 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3131 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3132 | |
| 3133 | /* FIXME: preserve source information better than this */ |
| 3134 | SourceRange SR(TL.getNameLoc()); |
| 3135 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3136 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3137 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3138 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3139 | if (!NNS) |
| 3140 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3141 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3142 | QualType Result; |
| 3143 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3144 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3145 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3146 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3147 | if (NewTemplateId.isNull()) |
| 3148 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3150 | if (!getDerived().AlwaysRebuild() && |
| 3151 | NNS == T->getQualifier() && |
| 3152 | NewTemplateId == QualType(TemplateId, 0)) |
| 3153 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3155 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3156 | NewTemplateId); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3157 | } else { |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3158 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3159 | T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3160 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3161 | if (Result.isNull()) |
| 3162 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3163 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3164 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3165 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3166 | |
| 3167 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3170 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3171 | QualType |
| 3172 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3173 | ObjCInterfaceTypeLoc TL, |
| 3174 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3175 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 3176 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3178 | |
| 3179 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3180 | QualType |
| 3181 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3182 | ObjCObjectPointerTypeLoc TL, |
| 3183 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3184 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3185 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3188 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3189 | // Statement transformation |
| 3190 | //===----------------------------------------------------------------------===// |
| 3191 | template<typename Derived> |
| 3192 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3193 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3194 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | template<typename Derived> |
| 3198 | Sema::OwningStmtResult |
| 3199 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3200 | return getDerived().TransformCompoundStmt(S, false); |
| 3201 | } |
| 3202 | |
| 3203 | template<typename Derived> |
| 3204 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3205 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3206 | bool IsStmtExpr) { |
| 3207 | bool SubStmtChanged = false; |
| 3208 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3209 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3210 | B != BEnd; ++B) { |
| 3211 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3212 | if (Result.isInvalid()) |
| 3213 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3214 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3215 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3216 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3218 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3219 | if (!getDerived().AlwaysRebuild() && |
| 3220 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3221 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3222 | |
| 3223 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3224 | move_arg(Statements), |
| 3225 | S->getRBracLoc(), |
| 3226 | IsStmtExpr); |
| 3227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3228 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3229 | template<typename Derived> |
| 3230 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3231 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3232 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3233 | { |
| 3234 | // The case value expressions are not potentially evaluated. |
| 3235 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3236 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3237 | // Transform the left-hand case value. |
| 3238 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3239 | if (LHS.isInvalid()) |
| 3240 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3242 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3243 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3244 | if (RHS.isInvalid()) |
| 3245 | return SemaRef.StmtError(); |
| 3246 | } |
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 | // Build the case statement. |
| 3249 | // Case statements are always rebuilt so that they will attached to their |
| 3250 | // transformed switch statement. |
| 3251 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3252 | move(LHS), |
| 3253 | S->getEllipsisLoc(), |
| 3254 | move(RHS), |
| 3255 | S->getColonLoc()); |
| 3256 | if (Case.isInvalid()) |
| 3257 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3258 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3259 | // Transform the statement following the case |
| 3260 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3261 | if (SubStmt.isInvalid()) |
| 3262 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3263 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3264 | // Attach the body to the case statement |
| 3265 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3266 | } |
| 3267 | |
| 3268 | template<typename Derived> |
| 3269 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | // Transform the statement following the default case |
| 3272 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3273 | if (SubStmt.isInvalid()) |
| 3274 | return SemaRef.StmtError(); |
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 | // Default statements are always rebuilt |
| 3277 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3278 | move(SubStmt)); |
| 3279 | } |
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 | template<typename Derived> |
| 3282 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3283 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3285 | if (SubStmt.isInvalid()) |
| 3286 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3288 | // FIXME: Pass the real colon location in. |
| 3289 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3290 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3291 | move(SubStmt)); |
| 3292 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3293 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3294 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | Sema::OwningStmtResult |
| 3296 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3297 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3298 | OwningExprResult Cond(SemaRef); |
| 3299 | VarDecl *ConditionVar = 0; |
| 3300 | if (S->getConditionVariable()) { |
| 3301 | ConditionVar |
| 3302 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3303 | getDerived().TransformDefinition( |
| 3304 | S->getConditionVariable()->getLocation(), |
| 3305 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3306 | if (!ConditionVar) |
| 3307 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3308 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3309 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3310 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3311 | if (Cond.isInvalid()) |
| 3312 | return SemaRef.StmtError(); |
| 3313 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3314 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3315 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | // Transform the "then" branch. |
| 3318 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3319 | if (Then.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 "else" branch. |
| 3323 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3324 | if (Else.isInvalid()) |
| 3325 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3327 | if (!getDerived().AlwaysRebuild() && |
| 3328 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3329 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3330 | Then.get() == S->getThen() && |
| 3331 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 | return SemaRef.Owned(S->Retain()); |
| 3333 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3334 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3335 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | template<typename Derived> |
| 3340 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3343 | OwningExprResult Cond(SemaRef); |
| 3344 | VarDecl *ConditionVar = 0; |
| 3345 | if (S->getConditionVariable()) { |
| 3346 | ConditionVar |
| 3347 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3348 | getDerived().TransformDefinition( |
| 3349 | S->getConditionVariable()->getLocation(), |
| 3350 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3351 | if (!ConditionVar) |
| 3352 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3353 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3354 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3355 | |
| 3356 | if (Cond.isInvalid()) |
| 3357 | return SemaRef.StmtError(); |
| 3358 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3360 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3361 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3363 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3364 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3365 | if (Switch.isInvalid()) |
| 3366 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | // Transform the body of the switch statement. |
| 3369 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3370 | if (Body.isInvalid()) |
| 3371 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3372 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3373 | // Complete the switch statement. |
| 3374 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3375 | move(Body)); |
| 3376 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3377 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3378 | template<typename Derived> |
| 3379 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3380 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3381 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3382 | OwningExprResult Cond(SemaRef); |
| 3383 | VarDecl *ConditionVar = 0; |
| 3384 | if (S->getConditionVariable()) { |
| 3385 | ConditionVar |
| 3386 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3387 | getDerived().TransformDefinition( |
| 3388 | S->getConditionVariable()->getLocation(), |
| 3389 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3390 | if (!ConditionVar) |
| 3391 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3392 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3393 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3394 | |
| 3395 | if (Cond.isInvalid()) |
| 3396 | return SemaRef.StmtError(); |
| 3397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3398 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3399 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3401 | // Transform the body |
| 3402 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3403 | if (Body.isInvalid()) |
| 3404 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | if (!getDerived().AlwaysRebuild() && |
| 3407 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3408 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3409 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | return SemaRef.Owned(S->Retain()); |
| 3411 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3412 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3413 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3415 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3416 | template<typename Derived> |
| 3417 | Sema::OwningStmtResult |
| 3418 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3419 | // Transform the condition |
| 3420 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3421 | if (Cond.isInvalid()) |
| 3422 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3423 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3424 | // Transform the body |
| 3425 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3426 | if (Body.isInvalid()) |
| 3427 | return SemaRef.StmtError(); |
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() && |
| 3430 | Cond.get() == S->getCond() && |
| 3431 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | return SemaRef.Owned(S->Retain()); |
| 3433 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3435 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3436 | S->getRParenLoc()); |
| 3437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3439 | template<typename Derived> |
| 3440 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | // Transform the initialization statement |
| 3443 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3444 | if (Init.isInvalid()) |
| 3445 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3448 | OwningExprResult Cond(SemaRef); |
| 3449 | VarDecl *ConditionVar = 0; |
| 3450 | if (S->getConditionVariable()) { |
| 3451 | ConditionVar |
| 3452 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3453 | getDerived().TransformDefinition( |
| 3454 | S->getConditionVariable()->getLocation(), |
| 3455 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3456 | if (!ConditionVar) |
| 3457 | return SemaRef.StmtError(); |
| 3458 | } else { |
| 3459 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3460 | |
| 3461 | if (Cond.isInvalid()) |
| 3462 | return SemaRef.StmtError(); |
| 3463 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3465 | // Transform the increment |
| 3466 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3467 | if (Inc.isInvalid()) |
| 3468 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3470 | // Transform the body |
| 3471 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3472 | if (Body.isInvalid()) |
| 3473 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3474 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3475 | if (!getDerived().AlwaysRebuild() && |
| 3476 | Init.get() == S->getInit() && |
| 3477 | Cond.get() == S->getCond() && |
| 3478 | Inc.get() == S->getInc() && |
| 3479 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | return SemaRef.Owned(S->Retain()); |
| 3481 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3482 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3483 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3484 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3485 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3486 | S->getRParenLoc(), move(Body)); |
| 3487 | } |
| 3488 | |
| 3489 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3490 | Sema::OwningStmtResult |
| 3491 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3492 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3493 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3494 | S->getLabel()); |
| 3495 | } |
| 3496 | |
| 3497 | template<typename Derived> |
| 3498 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3499 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3500 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3501 | if (Target.isInvalid()) |
| 3502 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3504 | if (!getDerived().AlwaysRebuild() && |
| 3505 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3507 | |
| 3508 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3509 | move(Target)); |
| 3510 | } |
| 3511 | |
| 3512 | template<typename Derived> |
| 3513 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3515 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3518 | template<typename Derived> |
| 3519 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3520 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3521 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | template<typename Derived> |
| 3525 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3527 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3528 | if (Result.isInvalid()) |
| 3529 | return SemaRef.StmtError(); |
| 3530 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3532 | // to tell whether the return type of the function has changed. |
| 3533 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | template<typename Derived> |
| 3537 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3538 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3539 | bool DeclChanged = false; |
| 3540 | llvm::SmallVector<Decl *, 4> Decls; |
| 3541 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3542 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3543 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3544 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | if (!Transformed) |
| 3546 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3547 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3548 | if (Transformed != *D) |
| 3549 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3550 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3551 | Decls.push_back(Transformed); |
| 3552 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3554 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | return SemaRef.Owned(S->Retain()); |
| 3556 | |
| 3557 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3558 | S->getStartLoc(), S->getEndLoc()); |
| 3559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3560 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3561 | template<typename Derived> |
| 3562 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3564 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | template<typename Derived> |
| 3569 | Sema::OwningStmtResult |
| 3570 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3571 | |
| 3572 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3573 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3574 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3575 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3576 | OwningExprResult AsmString(SemaRef); |
| 3577 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3578 | |
| 3579 | bool ExprsChanged = false; |
| 3580 | |
| 3581 | // Go through the outputs. |
| 3582 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3583 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3584 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3585 | // No need to transform the constraint literal. |
| 3586 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3587 | |
| 3588 | // Transform the output expr. |
| 3589 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3590 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3591 | if (Result.isInvalid()) |
| 3592 | return SemaRef.StmtError(); |
| 3593 | |
| 3594 | ExprsChanged |= Result.get() != OutputExpr; |
| 3595 | |
| 3596 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3597 | } |
| 3598 | |
| 3599 | // Go through the inputs. |
| 3600 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3601 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3602 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3603 | // No need to transform the constraint literal. |
| 3604 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3605 | |
| 3606 | // Transform the input expr. |
| 3607 | Expr *InputExpr = S->getInputExpr(I); |
| 3608 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3609 | if (Result.isInvalid()) |
| 3610 | return SemaRef.StmtError(); |
| 3611 | |
| 3612 | ExprsChanged |= Result.get() != InputExpr; |
| 3613 | |
| 3614 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3615 | } |
| 3616 | |
| 3617 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3618 | return SemaRef.Owned(S->Retain()); |
| 3619 | |
| 3620 | // Go through the clobbers. |
| 3621 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3622 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3623 | |
| 3624 | // No need to transform the asm string literal. |
| 3625 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3626 | |
| 3627 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3628 | S->isSimple(), |
| 3629 | S->isVolatile(), |
| 3630 | S->getNumOutputs(), |
| 3631 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3632 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3633 | move_arg(Constraints), |
| 3634 | move_arg(Exprs), |
| 3635 | move(AsmString), |
| 3636 | move_arg(Clobbers), |
| 3637 | S->getRParenLoc(), |
| 3638 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | |
| 3642 | template<typename Derived> |
| 3643 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3644 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3645 | // FIXME: Implement this |
| 3646 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3650 | template<typename Derived> |
| 3651 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3652 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3653 | // FIXME: Implement this |
| 3654 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3655 | return SemaRef.Owned(S->Retain()); |
| 3656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3658 | template<typename Derived> |
| 3659 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3660 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3661 | // FIXME: Implement this |
| 3662 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3664 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3666 | template<typename Derived> |
| 3667 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3668 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3669 | // FIXME: Implement this |
| 3670 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3671 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3673 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3674 | template<typename Derived> |
| 3675 | Sema::OwningStmtResult |
| 3676 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3678 | // FIXME: Implement this |
| 3679 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | template<typename Derived> |
| 3684 | Sema::OwningStmtResult |
| 3685 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3687 | // FIXME: Implement this |
| 3688 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | |
| 3693 | template<typename Derived> |
| 3694 | Sema::OwningStmtResult |
| 3695 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3696 | // Transform the exception declaration, if any. |
| 3697 | VarDecl *Var = 0; |
| 3698 | if (S->getExceptionDecl()) { |
| 3699 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3700 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3701 | ExceptionDecl->getDeclName()); |
| 3702 | |
| 3703 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3704 | if (T.isNull()) |
| 3705 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3706 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3707 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3708 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3709 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3710 | ExceptionDecl->getIdentifier(), |
| 3711 | ExceptionDecl->getLocation(), |
| 3712 | /*FIXME: Inaccurate*/ |
| 3713 | SourceRange(ExceptionDecl->getLocation())); |
| 3714 | if (!Var || Var->isInvalidDecl()) { |
| 3715 | if (Var) |
| 3716 | Var->Destroy(SemaRef.Context); |
| 3717 | return SemaRef.StmtError(); |
| 3718 | } |
| 3719 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3720 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3721 | // Transform the actual exception handler. |
| 3722 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3723 | if (Handler.isInvalid()) { |
| 3724 | if (Var) |
| 3725 | Var->Destroy(SemaRef.Context); |
| 3726 | return SemaRef.StmtError(); |
| 3727 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3728 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3729 | if (!getDerived().AlwaysRebuild() && |
| 3730 | !Var && |
| 3731 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3732 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3733 | |
| 3734 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3735 | Var, |
| 3736 | move(Handler)); |
| 3737 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3739 | template<typename Derived> |
| 3740 | Sema::OwningStmtResult |
| 3741 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3742 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3743 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3744 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3745 | if (TryBlock.isInvalid()) |
| 3746 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3748 | // Transform the handlers. |
| 3749 | bool HandlerChanged = false; |
| 3750 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3751 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3753 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3754 | if (Handler.isInvalid()) |
| 3755 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3757 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3758 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3759 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3761 | if (!getDerived().AlwaysRebuild() && |
| 3762 | TryBlock.get() == S->getTryBlock() && |
| 3763 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3765 | |
| 3766 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3767 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3768 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3769 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3770 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | // Expression transformation |
| 3772 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | template<typename Derived> |
| 3774 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3775 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3776 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
| 3779 | template<typename Derived> |
| 3780 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3781 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3782 | NestedNameSpecifier *Qualifier = 0; |
| 3783 | if (E->getQualifier()) { |
| 3784 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3785 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3786 | if (!Qualifier) |
| 3787 | return SemaRef.ExprError(); |
| 3788 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3789 | |
| 3790 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3791 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 3792 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3793 | if (!ND) |
| 3794 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3796 | if (!getDerived().AlwaysRebuild() && |
| 3797 | Qualifier == E->getQualifier() && |
| 3798 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3799 | !E->hasExplicitTemplateArgumentList()) { |
| 3800 | |
| 3801 | // Mark it referenced in the new context regardless. |
| 3802 | // FIXME: this is a bit instantiation-specific. |
| 3803 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3804 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3806 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3807 | |
| 3808 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3809 | if (E->hasExplicitTemplateArgumentList()) { |
| 3810 | TemplateArgs = &TransArgs; |
| 3811 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3812 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3813 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3814 | TemplateArgumentLoc Loc; |
| 3815 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3816 | return SemaRef.ExprError(); |
| 3817 | TransArgs.addArgument(Loc); |
| 3818 | } |
| 3819 | } |
| 3820 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3821 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3822 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3823 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3824 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3825 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3826 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3827 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3828 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3830 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3831 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3833 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3834 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3838 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3839 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3842 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3843 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3845 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3846 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3847 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3850 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3851 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | return SemaRef.Owned(E->Retain()); |
| 3853 | } |
| 3854 | |
| 3855 | template<typename Derived> |
| 3856 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3857 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3859 | if (SubExpr.isInvalid()) |
| 3860 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3862 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | return SemaRef.Owned(E->Retain()); |
| 3864 | |
| 3865 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3866 | E->getRParen()); |
| 3867 | } |
| 3868 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3869 | template<typename Derived> |
| 3870 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3871 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3872 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3873 | if (SubExpr.isInvalid()) |
| 3874 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3876 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | return SemaRef.Owned(E->Retain()); |
| 3878 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3879 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3880 | E->getOpcode(), |
| 3881 | move(SubExpr)); |
| 3882 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3885 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3886 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3887 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3888 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3889 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3890 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3891 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3892 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3894 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3895 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3897 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3898 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3899 | E->getSourceRange()); |
| 3900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3904 | // C++0x [expr.sizeof]p1: |
| 3905 | // The operand is either an expression, which is an unevaluated operand |
| 3906 | // [...] |
| 3907 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3908 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3909 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3910 | if (SubExpr.isInvalid()) |
| 3911 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3912 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3913 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3914 | return SemaRef.Owned(E->Retain()); |
| 3915 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3917 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3918 | E->isSizeOf(), |
| 3919 | E->getSourceRange()); |
| 3920 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3921 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3922 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3923 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3924 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3926 | if (LHS.isInvalid()) |
| 3927 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3930 | if (RHS.isInvalid()) |
| 3931 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3932 | |
| 3933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | if (!getDerived().AlwaysRebuild() && |
| 3935 | LHS.get() == E->getLHS() && |
| 3936 | RHS.get() == E->getRHS()) |
| 3937 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3939 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3940 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3941 | move(RHS), |
| 3942 | E->getRBracketLoc()); |
| 3943 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | |
| 3945 | template<typename Derived> |
| 3946 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3947 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3948 | // Transform the callee. |
| 3949 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3950 | if (Callee.isInvalid()) |
| 3951 | return SemaRef.ExprError(); |
| 3952 | |
| 3953 | // Transform arguments. |
| 3954 | bool ArgChanged = false; |
| 3955 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3956 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3957 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3958 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3959 | if (Arg.isInvalid()) |
| 3960 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3961 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3962 | // FIXME: Wrong source location information for the ','. |
| 3963 | FakeCommaLocs.push_back( |
| 3964 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
| 3966 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3967 | Args.push_back(Arg.takeAs<Expr>()); |
| 3968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3969 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | if (!getDerived().AlwaysRebuild() && |
| 3971 | Callee.get() == E->getCallee() && |
| 3972 | !ArgChanged) |
| 3973 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3977 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3978 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3979 | move_arg(Args), |
| 3980 | FakeCommaLocs.data(), |
| 3981 | E->getRParenLoc()); |
| 3982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
| 3984 | template<typename Derived> |
| 3985 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3986 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3987 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3988 | if (Base.isInvalid()) |
| 3989 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3990 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3991 | NestedNameSpecifier *Qualifier = 0; |
| 3992 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3994 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3995 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3996 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3997 | return SemaRef.ExprError(); |
| 3998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4000 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4001 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4002 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | if (!Member) |
| 4004 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4006 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4007 | if (FoundDecl == E->getMemberDecl()) { |
| 4008 | FoundDecl = Member; |
| 4009 | } else { |
| 4010 | FoundDecl = cast_or_null<NamedDecl>( |
| 4011 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4012 | if (!FoundDecl) |
| 4013 | return SemaRef.ExprError(); |
| 4014 | } |
| 4015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4016 | if (!getDerived().AlwaysRebuild() && |
| 4017 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4018 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4019 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4020 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4021 | !E->hasExplicitTemplateArgumentList()) { |
| 4022 | |
| 4023 | // Mark it referenced in the new context regardless. |
| 4024 | // FIXME: this is a bit instantiation-specific. |
| 4025 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4026 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4027 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4029 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4030 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4031 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4032 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4033 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4034 | TemplateArgumentLoc Loc; |
| 4035 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4036 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4037 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4038 | } |
| 4039 | } |
| 4040 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4041 | // FIXME: Bogus source location for the operator |
| 4042 | SourceLocation FakeOperatorLoc |
| 4043 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4044 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4045 | // FIXME: to do this check properly, we will need to preserve the |
| 4046 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4047 | // base (and therefore couldn't do the check) and a |
| 4048 | // nested-name-qualifier (and therefore could do the lookup). |
| 4049 | NamedDecl *FirstQualifierInScope = 0; |
| 4050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4052 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4053 | Qualifier, |
| 4054 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4055 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4056 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4057 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4058 | (E->hasExplicitTemplateArgumentList() |
| 4059 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4060 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4063 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4065 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4066 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4067 | if (LHS.isInvalid()) |
| 4068 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4070 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4071 | if (RHS.isInvalid()) |
| 4072 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4074 | if (!getDerived().AlwaysRebuild() && |
| 4075 | LHS.get() == E->getLHS() && |
| 4076 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4077 | return SemaRef.Owned(E->Retain()); |
| 4078 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4079 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4080 | move(LHS), move(RHS)); |
| 4081 | } |
| 4082 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | Sema::OwningExprResult |
| 4085 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4086 | CompoundAssignOperator *E) { |
| 4087 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | } |
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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4092 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4094 | if (Cond.isInvalid()) |
| 4095 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4098 | if (LHS.isInvalid()) |
| 4099 | return SemaRef.ExprError(); |
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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4102 | if (RHS.isInvalid()) |
| 4103 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4104 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4105 | if (!getDerived().AlwaysRebuild() && |
| 4106 | Cond.get() == E->getCond() && |
| 4107 | LHS.get() == E->getLHS() && |
| 4108 | RHS.get() == E->getRHS()) |
| 4109 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
| 4111 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4112 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4114 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4115 | move(RHS)); |
| 4116 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | |
| 4118 | template<typename Derived> |
| 4119 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4120 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4121 | // Implicit casts are eliminated during transformation, since they |
| 4122 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4123 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4126 | template<typename Derived> |
| 4127 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4128 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4129 | TypeSourceInfo *OldT; |
| 4130 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4131 | { |
| 4132 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4134 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4135 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4137 | OldT = E->getTypeInfoAsWritten(); |
| 4138 | NewT = getDerived().TransformType(OldT); |
| 4139 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4140 | return SemaRef.ExprError(); |
| 4141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4142 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4143 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4144 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4145 | if (SubExpr.isInvalid()) |
| 4146 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4148 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4149 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4151 | return SemaRef.Owned(E->Retain()); |
| 4152 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4153 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4154 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | E->getRParenLoc(), |
| 4156 | move(SubExpr)); |
| 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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4161 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4162 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4163 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4164 | if (!NewT) |
| 4165 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4166 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4167 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4168 | if (Init.isInvalid()) |
| 4169 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4171 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4172 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4173 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4175 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4176 | // Note: the expression type doesn't necessarily match the |
| 4177 | // type-as-written, but that's okay, because it should always be |
| 4178 | // derivable from the initializer. |
| 4179 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4180 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4182 | move(Init)); |
| 4183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | template<typename Derived> |
| 4186 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4187 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4189 | if (Base.isInvalid()) |
| 4190 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | if (!getDerived().AlwaysRebuild() && |
| 4193 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4194 | return SemaRef.Owned(E->Retain()); |
| 4195 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4199 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4200 | E->getAccessorLoc(), |
| 4201 | E->getAccessor()); |
| 4202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4204 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4206 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4209 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4210 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4211 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4212 | if (Init.isInvalid()) |
| 4213 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4216 | Inits.push_back(Init.takeAs<Expr>()); |
| 4217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4220 | return SemaRef.Owned(E->Retain()); |
| 4221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4223 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4224 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | template<typename Derived> |
| 4227 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4228 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4231 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4233 | if (Init.isInvalid()) |
| 4234 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4235 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4236 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4238 | bool ExprChanged = false; |
| 4239 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4240 | DEnd = E->designators_end(); |
| 4241 | D != DEnd; ++D) { |
| 4242 | if (D->isFieldDesignator()) { |
| 4243 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4244 | D->getDotLoc(), |
| 4245 | D->getFieldLoc())); |
| 4246 | continue; |
| 4247 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4248 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4249 | if (D->isArrayDesignator()) { |
| 4250 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4251 | if (Index.isInvalid()) |
| 4252 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | |
| 4254 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4256 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4257 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4258 | ArrayExprs.push_back(Index.release()); |
| 4259 | continue; |
| 4260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4265 | if (Start.isInvalid()) |
| 4266 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4267 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4268 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4269 | if (End.isInvalid()) |
| 4270 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | |
| 4272 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4273 | End.get(), |
| 4274 | D->getLBracketLoc(), |
| 4275 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4276 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4277 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4278 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4280 | ArrayExprs.push_back(Start.release()); |
| 4281 | ArrayExprs.push_back(End.release()); |
| 4282 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4284 | if (!getDerived().AlwaysRebuild() && |
| 4285 | Init.get() == E->getInit() && |
| 4286 | !ExprChanged) |
| 4287 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4290 | E->getEqualOrColonLoc(), |
| 4291 | E->usesGNUSyntax(), move(Init)); |
| 4292 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4293 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4294 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4297 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4298 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4299 | |
| 4300 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4301 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4302 | QualType T = getDerived().TransformType(E->getType()); |
| 4303 | if (T.isNull()) |
| 4304 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4305 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | if (!getDerived().AlwaysRebuild() && |
| 4307 | T == E->getType()) |
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().RebuildImplicitValueInitExpr(T); |
| 4311 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4315 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4316 | // FIXME: Do we want the type as written? |
| 4317 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | { |
| 4320 | // FIXME: Source location isn't quite accurate. |
| 4321 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4322 | T = getDerived().TransformType(E->getType()); |
| 4323 | if (T.isNull()) |
| 4324 | return SemaRef.ExprError(); |
| 4325 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4326 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4327 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4328 | if (SubExpr.isInvalid()) |
| 4329 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | if (!getDerived().AlwaysRebuild() && |
| 4332 | T == E->getType() && |
| 4333 | SubExpr.get() == E->getSubExpr()) |
| 4334 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4337 | T, E->getRParenLoc()); |
| 4338 | } |
| 4339 | |
| 4340 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4341 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4342 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | bool ArgumentChanged = false; |
| 4344 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4345 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4346 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4347 | if (Init.isInvalid()) |
| 4348 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4349 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4351 | Inits.push_back(Init.takeAs<Expr>()); |
| 4352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4354 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4355 | move_arg(Inits), |
| 4356 | E->getRParenLoc()); |
| 4357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | /// \brief Transform an address-of-label expression. |
| 4360 | /// |
| 4361 | /// By default, the transformation of an address-of-label expression always |
| 4362 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4363 | /// the corresponding label statement by semantic analysis. |
| 4364 | template<typename Derived> |
| 4365 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4366 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4368 | E->getLabel()); |
| 4369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
| 4371 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4372 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4373 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4376 | if (SubStmt.isInvalid()) |
| 4377 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | if (!getDerived().AlwaysRebuild() && |
| 4380 | SubStmt.get() == E->getSubStmt()) |
| 4381 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4382 | |
| 4383 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | move(SubStmt), |
| 4385 | E->getRParenLoc()); |
| 4386 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | template<typename Derived> |
| 4389 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4390 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4391 | QualType T1, T2; |
| 4392 | { |
| 4393 | // FIXME: Source location isn't quite accurate. |
| 4394 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4395 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4396 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4397 | if (T1.isNull()) |
| 4398 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4401 | if (T2.isNull()) |
| 4402 | return SemaRef.ExprError(); |
| 4403 | } |
| 4404 | |
| 4405 | if (!getDerived().AlwaysRebuild() && |
| 4406 | T1 == E->getArgType1() && |
| 4407 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | return SemaRef.Owned(E->Retain()); |
| 4409 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4411 | T1, T2, E->getRParenLoc()); |
| 4412 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | template<typename Derived> |
| 4415 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4416 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4418 | if (Cond.isInvalid()) |
| 4419 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4422 | if (LHS.isInvalid()) |
| 4423 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4426 | if (RHS.isInvalid()) |
| 4427 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4429 | if (!getDerived().AlwaysRebuild() && |
| 4430 | Cond.get() == E->getCond() && |
| 4431 | LHS.get() == E->getLHS() && |
| 4432 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | return SemaRef.Owned(E->Retain()); |
| 4434 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4436 | move(Cond), move(LHS), move(RHS), |
| 4437 | E->getRParenLoc()); |
| 4438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4442 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4443 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | template<typename Derived> |
| 4447 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4448 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4449 | switch (E->getOperator()) { |
| 4450 | case OO_New: |
| 4451 | case OO_Delete: |
| 4452 | case OO_Array_New: |
| 4453 | case OO_Array_Delete: |
| 4454 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4455 | return SemaRef.ExprError(); |
| 4456 | |
| 4457 | case OO_Call: { |
| 4458 | // This is a call to an object's operator(). |
| 4459 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4460 | |
| 4461 | // Transform the object itself. |
| 4462 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4463 | if (Object.isInvalid()) |
| 4464 | return SemaRef.ExprError(); |
| 4465 | |
| 4466 | // FIXME: Poor location information |
| 4467 | SourceLocation FakeLParenLoc |
| 4468 | = SemaRef.PP.getLocForEndOfToken( |
| 4469 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4470 | |
| 4471 | // Transform the call arguments. |
| 4472 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4473 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4474 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4475 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4476 | break; |
| 4477 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4478 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4479 | if (Arg.isInvalid()) |
| 4480 | return SemaRef.ExprError(); |
| 4481 | |
| 4482 | // FIXME: Poor source location information. |
| 4483 | SourceLocation FakeCommaLoc |
| 4484 | = SemaRef.PP.getLocForEndOfToken( |
| 4485 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4486 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4487 | Args.push_back(Arg.release()); |
| 4488 | } |
| 4489 | |
| 4490 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4491 | move_arg(Args), |
| 4492 | FakeCommaLocs.data(), |
| 4493 | E->getLocEnd()); |
| 4494 | } |
| 4495 | |
| 4496 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4497 | case OO_##Name: |
| 4498 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4499 | #include "clang/Basic/OperatorKinds.def" |
| 4500 | case OO_Subscript: |
| 4501 | // Handled below. |
| 4502 | break; |
| 4503 | |
| 4504 | case OO_Conditional: |
| 4505 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4506 | return SemaRef.ExprError(); |
| 4507 | |
| 4508 | case OO_None: |
| 4509 | case NUM_OVERLOADED_OPERATORS: |
| 4510 | llvm_unreachable("not an overloaded operator?"); |
| 4511 | return SemaRef.ExprError(); |
| 4512 | } |
| 4513 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4515 | if (Callee.isInvalid()) |
| 4516 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4518 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4519 | if (First.isInvalid()) |
| 4520 | return SemaRef.ExprError(); |
| 4521 | |
| 4522 | OwningExprResult Second(SemaRef); |
| 4523 | if (E->getNumArgs() == 2) { |
| 4524 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4525 | if (Second.isInvalid()) |
| 4526 | return SemaRef.ExprError(); |
| 4527 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | if (!getDerived().AlwaysRebuild() && |
| 4530 | Callee.get() == E->getCallee() && |
| 4531 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4533 | return SemaRef.Owned(E->Retain()); |
| 4534 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4535 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4536 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4537 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4538 | move(First), |
| 4539 | move(Second)); |
| 4540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4541 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4542 | template<typename Derived> |
| 4543 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4544 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4545 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4548 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4550 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4551 | TypeSourceInfo *OldT; |
| 4552 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | { |
| 4554 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4555 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4556 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4557 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4559 | OldT = E->getTypeInfoAsWritten(); |
| 4560 | NewT = getDerived().TransformType(OldT); |
| 4561 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4562 | return SemaRef.ExprError(); |
| 4563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4565 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4566 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | if (SubExpr.isInvalid()) |
| 4568 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4571 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | return SemaRef.Owned(E->Retain()); |
| 4574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4578 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4579 | SourceLocation FakeRParenLoc |
| 4580 | = SemaRef.PP.getLocForEndOfToken( |
| 4581 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4582 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4585 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4586 | FakeRAngleLoc, |
| 4587 | FakeRAngleLoc, |
| 4588 | move(SubExpr), |
| 4589 | FakeRParenLoc); |
| 4590 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4591 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4592 | template<typename Derived> |
| 4593 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4594 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4595 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4596 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4597 | |
| 4598 | template<typename Derived> |
| 4599 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4600 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4601 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | template<typename Derived> |
| 4605 | Sema::OwningExprResult |
| 4606 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4607 | CXXReinterpretCastExpr *E) { |
| 4608 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4609 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4610 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | template<typename Derived> |
| 4612 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4613 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4614 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | template<typename Derived> |
| 4618 | Sema::OwningExprResult |
| 4619 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4620 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4621 | TypeSourceInfo *OldT; |
| 4622 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4623 | { |
| 4624 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4625 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4626 | OldT = E->getTypeInfoAsWritten(); |
| 4627 | NewT = getDerived().TransformType(OldT); |
| 4628 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4629 | return SemaRef.ExprError(); |
| 4630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4631 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4632 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4633 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4634 | if (SubExpr.isInvalid()) |
| 4635 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4636 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4638 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | return SemaRef.Owned(E->Retain()); |
| 4641 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4642 | // FIXME: The end of the type's source range is wrong |
| 4643 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4644 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4645 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4647 | move(SubExpr), |
| 4648 | E->getRParenLoc()); |
| 4649 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | template<typename Derived> |
| 4652 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4653 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4654 | if (E->isTypeOperand()) { |
| 4655 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4657 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4658 | if (T.isNull()) |
| 4659 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4660 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4661 | if (!getDerived().AlwaysRebuild() && |
| 4662 | T == E->getTypeOperand()) |
| 4663 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4665 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4666 | /*FIXME:*/E->getLocStart(), |
| 4667 | T, |
| 4668 | E->getLocEnd()); |
| 4669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4671 | // We don't know whether the expression is potentially evaluated until |
| 4672 | // after we perform semantic analysis, so the expression is potentially |
| 4673 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4674 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4675 | Action::PotentiallyPotentiallyEvaluated); |
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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4678 | if (SubExpr.isInvalid()) |
| 4679 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4681 | if (!getDerived().AlwaysRebuild() && |
| 4682 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | return SemaRef.Owned(E->Retain()); |
| 4684 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4686 | /*FIXME:*/E->getLocStart(), |
| 4687 | move(SubExpr), |
| 4688 | E->getLocEnd()); |
| 4689 | } |
| 4690 | |
| 4691 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4692 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4693 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4697 | template<typename Derived> |
| 4698 | Sema::OwningExprResult |
| 4699 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4700 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4701 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4703 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4704 | template<typename Derived> |
| 4705 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4706 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4707 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4708 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4709 | QualType T = getDerived().TransformType(E->getType()); |
| 4710 | if (T.isNull()) |
| 4711 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4712 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | if (!getDerived().AlwaysRebuild() && |
| 4714 | T == E->getType()) |
| 4715 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4716 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4717 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4718 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4719 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4720 | template<typename Derived> |
| 4721 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4722 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4724 | if (SubExpr.isInvalid()) |
| 4725 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4726 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4727 | if (!getDerived().AlwaysRebuild() && |
| 4728 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4729 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4730 | |
| 4731 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4733 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4734 | template<typename Derived> |
| 4735 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4736 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4737 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4738 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 4739 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4740 | if (!Param) |
| 4741 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4742 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4743 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4744 | Param == E->getParam()) |
| 4745 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4747 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | template<typename Derived> |
| 4751 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4752 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4753 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4754 | |
| 4755 | QualType T = getDerived().TransformType(E->getType()); |
| 4756 | if (T.isNull()) |
| 4757 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4759 | if (!getDerived().AlwaysRebuild() && |
| 4760 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4761 | return SemaRef.Owned(E->Retain()); |
| 4762 | |
| 4763 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4765 | T, |
| 4766 | E->getRParenLoc()); |
| 4767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4769 | template<typename Derived> |
| 4770 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4771 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4772 | // Transform the type that we're allocating |
| 4773 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4774 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4775 | if (AllocType.isNull()) |
| 4776 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4778 | // Transform the size of the array we're allocating (if any). |
| 4779 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4780 | if (ArraySize.isInvalid()) |
| 4781 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4783 | // Transform the placement arguments (if any). |
| 4784 | bool ArgumentChanged = false; |
| 4785 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4786 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4787 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4788 | if (Arg.isInvalid()) |
| 4789 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4792 | PlacementArgs.push_back(Arg.take()); |
| 4793 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4795 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4796 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4797 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4798 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4799 | if (Arg.isInvalid()) |
| 4800 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4802 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4803 | ConstructorArgs.push_back(Arg.take()); |
| 4804 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4805 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4806 | // Transform constructor, new operator, and delete operator. |
| 4807 | CXXConstructorDecl *Constructor = 0; |
| 4808 | if (E->getConstructor()) { |
| 4809 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4810 | getDerived().TransformDecl(E->getLocStart(), |
| 4811 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4812 | if (!Constructor) |
| 4813 | return SemaRef.ExprError(); |
| 4814 | } |
| 4815 | |
| 4816 | FunctionDecl *OperatorNew = 0; |
| 4817 | if (E->getOperatorNew()) { |
| 4818 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4819 | getDerived().TransformDecl(E->getLocStart(), |
| 4820 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4821 | if (!OperatorNew) |
| 4822 | return SemaRef.ExprError(); |
| 4823 | } |
| 4824 | |
| 4825 | FunctionDecl *OperatorDelete = 0; |
| 4826 | if (E->getOperatorDelete()) { |
| 4827 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4828 | getDerived().TransformDecl(E->getLocStart(), |
| 4829 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4830 | if (!OperatorDelete) |
| 4831 | return SemaRef.ExprError(); |
| 4832 | } |
| 4833 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | if (!getDerived().AlwaysRebuild() && |
| 4835 | AllocType == E->getAllocatedType() && |
| 4836 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4837 | Constructor == E->getConstructor() && |
| 4838 | OperatorNew == E->getOperatorNew() && |
| 4839 | OperatorDelete == E->getOperatorDelete() && |
| 4840 | !ArgumentChanged) { |
| 4841 | // Mark any declarations we need as referenced. |
| 4842 | // FIXME: instantiation-specific. |
| 4843 | if (Constructor) |
| 4844 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 4845 | if (OperatorNew) |
| 4846 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 4847 | if (OperatorDelete) |
| 4848 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4849 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4851 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4852 | if (!ArraySize.get()) { |
| 4853 | // If no array size was specified, but the new expression was |
| 4854 | // instantiated with an array type (e.g., "new T" where T is |
| 4855 | // instantiated with "int[4]"), extract the outer bound from the |
| 4856 | // array type as our array size. We do this with constant and |
| 4857 | // dependently-sized array types. |
| 4858 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4859 | if (!ArrayT) { |
| 4860 | // Do nothing |
| 4861 | } else if (const ConstantArrayType *ConsArrayT |
| 4862 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4863 | ArraySize |
| 4864 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4865 | ConsArrayT->getSize(), |
| 4866 | SemaRef.Context.getSizeType(), |
| 4867 | /*FIXME:*/E->getLocStart())); |
| 4868 | AllocType = ConsArrayT->getElementType(); |
| 4869 | } else if (const DependentSizedArrayType *DepArrayT |
| 4870 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4871 | if (DepArrayT->getSizeExpr()) { |
| 4872 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4873 | AllocType = DepArrayT->getElementType(); |
| 4874 | } |
| 4875 | } |
| 4876 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4877 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4878 | E->isGlobalNew(), |
| 4879 | /*FIXME:*/E->getLocStart(), |
| 4880 | move_arg(PlacementArgs), |
| 4881 | /*FIXME:*/E->getLocStart(), |
| 4882 | E->isParenTypeId(), |
| 4883 | AllocType, |
| 4884 | /*FIXME:*/E->getLocStart(), |
| 4885 | /*FIXME:*/SourceRange(), |
| 4886 | move(ArraySize), |
| 4887 | /*FIXME:*/E->getLocStart(), |
| 4888 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4889 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4892 | template<typename Derived> |
| 4893 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4894 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4895 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4896 | if (Operand.isInvalid()) |
| 4897 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4898 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4899 | // Transform the delete operator, if known. |
| 4900 | FunctionDecl *OperatorDelete = 0; |
| 4901 | if (E->getOperatorDelete()) { |
| 4902 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4903 | getDerived().TransformDecl(E->getLocStart(), |
| 4904 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4905 | if (!OperatorDelete) |
| 4906 | return SemaRef.ExprError(); |
| 4907 | } |
| 4908 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4909 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4910 | Operand.get() == E->getArgument() && |
| 4911 | OperatorDelete == E->getOperatorDelete()) { |
| 4912 | // Mark any declarations we need as referenced. |
| 4913 | // FIXME: instantiation-specific. |
| 4914 | if (OperatorDelete) |
| 4915 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 4917 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4918 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4919 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4920 | E->isGlobalDelete(), |
| 4921 | E->isArrayForm(), |
| 4922 | move(Operand)); |
| 4923 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4924 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4925 | template<typename Derived> |
| 4926 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4927 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4928 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4929 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4930 | if (Base.isInvalid()) |
| 4931 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4932 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4933 | Sema::TypeTy *ObjectTypePtr = 0; |
| 4934 | bool MayBePseudoDestructor = false; |
| 4935 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4936 | E->getOperatorLoc(), |
| 4937 | E->isArrow()? tok::arrow : tok::period, |
| 4938 | ObjectTypePtr, |
| 4939 | MayBePseudoDestructor); |
| 4940 | if (Base.isInvalid()) |
| 4941 | return SemaRef.ExprError(); |
| 4942 | |
| 4943 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4944 | NestedNameSpecifier *Qualifier |
| 4945 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4946 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4947 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4948 | if (E->getQualifier() && !Qualifier) |
| 4949 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4951 | PseudoDestructorTypeStorage Destroyed; |
| 4952 | if (E->getDestroyedTypeInfo()) { |
| 4953 | TypeSourceInfo *DestroyedTypeInfo |
| 4954 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 4955 | if (!DestroyedTypeInfo) |
| 4956 | return SemaRef.ExprError(); |
| 4957 | Destroyed = DestroyedTypeInfo; |
| 4958 | } else if (ObjectType->isDependentType()) { |
| 4959 | // We aren't likely to be able to resolve the identifier down to a type |
| 4960 | // now anyway, so just retain the identifier. |
| 4961 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 4962 | E->getDestroyedTypeLoc()); |
| 4963 | } else { |
| 4964 | // Look for a destructor known with the given name. |
| 4965 | CXXScopeSpec SS; |
| 4966 | if (Qualifier) { |
| 4967 | SS.setScopeRep(Qualifier); |
| 4968 | SS.setRange(E->getQualifierRange()); |
| 4969 | } |
| 4970 | |
| 4971 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 4972 | *E->getDestroyedTypeIdentifier(), |
| 4973 | E->getDestroyedTypeLoc(), |
| 4974 | /*Scope=*/0, |
| 4975 | SS, ObjectTypePtr, |
| 4976 | false); |
| 4977 | if (!T) |
| 4978 | return SemaRef.ExprError(); |
| 4979 | |
| 4980 | Destroyed |
| 4981 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 4982 | E->getDestroyedTypeLoc()); |
| 4983 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4984 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4985 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4986 | if (E->getScopeTypeInfo()) { |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 4987 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
| 4988 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4989 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4990 | return SemaRef.ExprError(); |
| 4991 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4992 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4993 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4994 | E->getOperatorLoc(), |
| 4995 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4996 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 4997 | E->getQualifierRange(), |
| 4998 | ScopeTypeInfo, |
| 4999 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5000 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5001 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5002 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5003 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5004 | template<typename Derived> |
| 5005 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5006 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5007 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5008 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5009 | |
| 5010 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5011 | Sema::LookupOrdinaryName); |
| 5012 | |
| 5013 | // Transform all the decls. |
| 5014 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5015 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5016 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5017 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5018 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5019 | if (!InstD) { |
| 5020 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5021 | // This can happen because of dependent hiding. |
| 5022 | if (isa<UsingShadowDecl>(*I)) |
| 5023 | continue; |
| 5024 | else |
| 5025 | return SemaRef.ExprError(); |
| 5026 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5027 | |
| 5028 | // Expand using declarations. |
| 5029 | if (isa<UsingDecl>(InstD)) { |
| 5030 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5031 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5032 | E = UD->shadow_end(); I != E; ++I) |
| 5033 | R.addDecl(*I); |
| 5034 | continue; |
| 5035 | } |
| 5036 | |
| 5037 | R.addDecl(InstD); |
| 5038 | } |
| 5039 | |
| 5040 | // Resolve a kind, but don't do any further analysis. If it's |
| 5041 | // ambiguous, the callee needs to deal with it. |
| 5042 | R.resolveKind(); |
| 5043 | |
| 5044 | // Rebuild the nested-name qualifier, if present. |
| 5045 | CXXScopeSpec SS; |
| 5046 | NestedNameSpecifier *Qualifier = 0; |
| 5047 | if (Old->getQualifier()) { |
| 5048 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5049 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5050 | if (!Qualifier) |
| 5051 | return SemaRef.ExprError(); |
| 5052 | |
| 5053 | SS.setScopeRep(Qualifier); |
| 5054 | SS.setRange(Old->getQualifierRange()); |
| 5055 | } |
| 5056 | |
| 5057 | // If we have no template arguments, it's a normal declaration name. |
| 5058 | if (!Old->hasExplicitTemplateArgs()) |
| 5059 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5060 | |
| 5061 | // If we have template arguments, rebuild them, then rebuild the |
| 5062 | // templateid expression. |
| 5063 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5064 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5065 | TemplateArgumentLoc Loc; |
| 5066 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5067 | return SemaRef.ExprError(); |
| 5068 | TransArgs.addArgument(Loc); |
| 5069 | } |
| 5070 | |
| 5071 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5072 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5074 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | template<typename Derived> |
| 5076 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5077 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5081 | if (T.isNull()) |
| 5082 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5083 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5084 | if (!getDerived().AlwaysRebuild() && |
| 5085 | T == E->getQueriedType()) |
| 5086 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | // FIXME: Bad location information |
| 5089 | SourceLocation FakeLParenLoc |
| 5090 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | |
| 5092 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5093 | E->getLocStart(), |
| 5094 | /*FIXME:*/FakeLParenLoc, |
| 5095 | T, |
| 5096 | E->getLocEnd()); |
| 5097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5099 | template<typename Derived> |
| 5100 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5101 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5102 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5103 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5104 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5105 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5106 | if (!NNS) |
| 5107 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5108 | |
| 5109 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5110 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5111 | if (!Name) |
| 5112 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5113 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5114 | if (!E->hasExplicitTemplateArgs()) { |
| 5115 | if (!getDerived().AlwaysRebuild() && |
| 5116 | NNS == E->getQualifier() && |
| 5117 | Name == E->getDeclName()) |
| 5118 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5119 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5120 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5121 | E->getQualifierRange(), |
| 5122 | Name, E->getLocation(), |
| 5123 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5124 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5125 | |
| 5126 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5127 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5128 | TemplateArgumentLoc Loc; |
| 5129 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5130 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5131 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5132 | } |
| 5133 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5134 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5135 | E->getQualifierRange(), |
| 5136 | Name, E->getLocation(), |
| 5137 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | template<typename Derived> |
| 5141 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5142 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5143 | // CXXConstructExprs are always implicit, so when we have a |
| 5144 | // 1-argument construction we just transform that argument. |
| 5145 | if (E->getNumArgs() == 1 || |
| 5146 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5147 | return getDerived().TransformExpr(E->getArg(0)); |
| 5148 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5149 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5150 | |
| 5151 | QualType T = getDerived().TransformType(E->getType()); |
| 5152 | if (T.isNull()) |
| 5153 | return SemaRef.ExprError(); |
| 5154 | |
| 5155 | CXXConstructorDecl *Constructor |
| 5156 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5157 | getDerived().TransformDecl(E->getLocStart(), |
| 5158 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5159 | if (!Constructor) |
| 5160 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5162 | bool ArgumentChanged = false; |
| 5163 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5164 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5165 | ArgEnd = E->arg_end(); |
| 5166 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5167 | if (getDerived().DropCallArgument(*Arg)) { |
| 5168 | ArgumentChanged = true; |
| 5169 | break; |
| 5170 | } |
| 5171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5173 | if (TransArg.isInvalid()) |
| 5174 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5177 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5178 | } |
| 5179 | |
| 5180 | if (!getDerived().AlwaysRebuild() && |
| 5181 | T == E->getType() && |
| 5182 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5183 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5184 | // Mark the constructor as referenced. |
| 5185 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5186 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5187 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5190 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5191 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | move_arg(Args)); |
| 5193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5195 | /// \brief Transform a C++ temporary-binding expression. |
| 5196 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5197 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5198 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | template<typename Derived> |
| 5200 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5201 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5202 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5204 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5205 | /// \brief Transform a C++ reference-binding expression. |
| 5206 | /// |
| 5207 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5208 | /// transform the subexpression and return that. |
| 5209 | template<typename Derived> |
| 5210 | Sema::OwningExprResult |
| 5211 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5212 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5213 | } |
| 5214 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5215 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5216 | /// be destroyed after the expression is evaluated. |
| 5217 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5218 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5219 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5220 | template<typename Derived> |
| 5221 | Sema::OwningExprResult |
| 5222 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5223 | CXXExprWithTemporaries *E) { |
| 5224 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5226 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | template<typename Derived> |
| 5228 | Sema::OwningExprResult |
| 5229 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5230 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5232 | QualType T = getDerived().TransformType(E->getType()); |
| 5233 | if (T.isNull()) |
| 5234 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5235 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5236 | CXXConstructorDecl *Constructor |
| 5237 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5238 | getDerived().TransformDecl(E->getLocStart(), |
| 5239 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5240 | if (!Constructor) |
| 5241 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5243 | bool ArgumentChanged = false; |
| 5244 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5245 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5246 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5247 | ArgEnd = E->arg_end(); |
| 5248 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5249 | if (getDerived().DropCallArgument(*Arg)) { |
| 5250 | ArgumentChanged = true; |
| 5251 | break; |
| 5252 | } |
| 5253 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5254 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5255 | if (TransArg.isInvalid()) |
| 5256 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5259 | Args.push_back((Expr *)TransArg.release()); |
| 5260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5261 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5262 | if (!getDerived().AlwaysRebuild() && |
| 5263 | T == E->getType() && |
| 5264 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5265 | !ArgumentChanged) { |
| 5266 | // FIXME: Instantiation-specific |
| 5267 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5268 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5269 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5271 | // FIXME: Bogus location information |
| 5272 | SourceLocation CommaLoc; |
| 5273 | if (Args.size() > 1) { |
| 5274 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5275 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5276 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5277 | } |
| 5278 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5279 | T, |
| 5280 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5281 | move_arg(Args), |
| 5282 | &CommaLoc, |
| 5283 | E->getLocEnd()); |
| 5284 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5286 | template<typename Derived> |
| 5287 | Sema::OwningExprResult |
| 5288 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5289 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5290 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5291 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5292 | if (T.isNull()) |
| 5293 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5294 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5295 | bool ArgumentChanged = false; |
| 5296 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5297 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5298 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5299 | ArgEnd = E->arg_end(); |
| 5300 | Arg != ArgEnd; ++Arg) { |
| 5301 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5302 | if (TransArg.isInvalid()) |
| 5303 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5304 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5305 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5306 | FakeCommaLocs.push_back( |
| 5307 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5308 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5311 | if (!getDerived().AlwaysRebuild() && |
| 5312 | T == E->getTypeAsWritten() && |
| 5313 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5314 | return SemaRef.Owned(E->Retain()); |
| 5315 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5316 | // FIXME: we're faking the locations of the commas |
| 5317 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5318 | T, |
| 5319 | E->getLParenLoc(), |
| 5320 | move_arg(Args), |
| 5321 | FakeCommaLocs.data(), |
| 5322 | E->getRParenLoc()); |
| 5323 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5324 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5325 | template<typename Derived> |
| 5326 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5327 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5328 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5329 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5330 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5331 | Expr *OldBase; |
| 5332 | QualType BaseType; |
| 5333 | QualType ObjectType; |
| 5334 | if (!E->isImplicitAccess()) { |
| 5335 | OldBase = E->getBase(); |
| 5336 | Base = getDerived().TransformExpr(OldBase); |
| 5337 | if (Base.isInvalid()) |
| 5338 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5339 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5340 | // Start the member reference and compute the object's type. |
| 5341 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5342 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5343 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5344 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5345 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5346 | ObjectTy, |
| 5347 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5348 | if (Base.isInvalid()) |
| 5349 | return SemaRef.ExprError(); |
| 5350 | |
| 5351 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5352 | BaseType = ((Expr*) Base.get())->getType(); |
| 5353 | } else { |
| 5354 | OldBase = 0; |
| 5355 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5356 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5358 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5359 | // Transform the first part of the nested-name-specifier that qualifies |
| 5360 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5361 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5362 | = getDerived().TransformFirstQualifierInScope( |
| 5363 | E->getFirstQualifierFoundInScope(), |
| 5364 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5365 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5366 | NestedNameSpecifier *Qualifier = 0; |
| 5367 | if (E->getQualifier()) { |
| 5368 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5369 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5370 | ObjectType, |
| 5371 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5372 | if (!Qualifier) |
| 5373 | return SemaRef.ExprError(); |
| 5374 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5375 | |
| 5376 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5377 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5378 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5379 | if (!Name) |
| 5380 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5382 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5383 | // This is a reference to a member without an explicitly-specified |
| 5384 | // template argument list. Optimize for this common case. |
| 5385 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5386 | Base.get() == OldBase && |
| 5387 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5388 | Qualifier == E->getQualifier() && |
| 5389 | Name == E->getMember() && |
| 5390 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5391 | return SemaRef.Owned(E->Retain()); |
| 5392 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5393 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5394 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5395 | E->isArrow(), |
| 5396 | E->getOperatorLoc(), |
| 5397 | Qualifier, |
| 5398 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5399 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5400 | Name, |
| 5401 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5402 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5403 | } |
| 5404 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5405 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5406 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5407 | TemplateArgumentLoc Loc; |
| 5408 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5409 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5410 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5413 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5414 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5415 | E->isArrow(), |
| 5416 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5417 | Qualifier, |
| 5418 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5419 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5420 | Name, |
| 5421 | E->getMemberLoc(), |
| 5422 | &TransArgs); |
| 5423 | } |
| 5424 | |
| 5425 | template<typename Derived> |
| 5426 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5427 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5428 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5429 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5430 | QualType BaseType; |
| 5431 | if (!Old->isImplicitAccess()) { |
| 5432 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5433 | if (Base.isInvalid()) |
| 5434 | return SemaRef.ExprError(); |
| 5435 | BaseType = ((Expr*) Base.get())->getType(); |
| 5436 | } else { |
| 5437 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5438 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5439 | |
| 5440 | NestedNameSpecifier *Qualifier = 0; |
| 5441 | if (Old->getQualifier()) { |
| 5442 | Qualifier |
| 5443 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5444 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5445 | if (Qualifier == 0) |
| 5446 | return SemaRef.ExprError(); |
| 5447 | } |
| 5448 | |
| 5449 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5450 | Sema::LookupOrdinaryName); |
| 5451 | |
| 5452 | // Transform all the decls. |
| 5453 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5454 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5455 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5456 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5457 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5458 | if (!InstD) { |
| 5459 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5460 | // This can happen because of dependent hiding. |
| 5461 | if (isa<UsingShadowDecl>(*I)) |
| 5462 | continue; |
| 5463 | else |
| 5464 | return SemaRef.ExprError(); |
| 5465 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5466 | |
| 5467 | // Expand using declarations. |
| 5468 | if (isa<UsingDecl>(InstD)) { |
| 5469 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5470 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5471 | E = UD->shadow_end(); I != E; ++I) |
| 5472 | R.addDecl(*I); |
| 5473 | continue; |
| 5474 | } |
| 5475 | |
| 5476 | R.addDecl(InstD); |
| 5477 | } |
| 5478 | |
| 5479 | R.resolveKind(); |
| 5480 | |
| 5481 | TemplateArgumentListInfo TransArgs; |
| 5482 | if (Old->hasExplicitTemplateArgs()) { |
| 5483 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5484 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5485 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5486 | TemplateArgumentLoc Loc; |
| 5487 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5488 | Loc)) |
| 5489 | return SemaRef.ExprError(); |
| 5490 | TransArgs.addArgument(Loc); |
| 5491 | } |
| 5492 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5493 | |
| 5494 | // FIXME: to do this check properly, we will need to preserve the |
| 5495 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5496 | // base (and therefore couldn't do the check) and a |
| 5497 | // nested-name-qualifier (and therefore could do the lookup). |
| 5498 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5499 | |
| 5500 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5501 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5502 | Old->getOperatorLoc(), |
| 5503 | Old->isArrow(), |
| 5504 | Qualifier, |
| 5505 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5506 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5507 | R, |
| 5508 | (Old->hasExplicitTemplateArgs() |
| 5509 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | template<typename Derived> |
| 5513 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5514 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5515 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5518 | template<typename Derived> |
| 5519 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5520 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5521 | TypeSourceInfo *EncodedTypeInfo |
| 5522 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5523 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5524 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5526 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5527 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5528 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5529 | |
| 5530 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5531 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5532 | E->getRParenLoc()); |
| 5533 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5534 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5535 | template<typename Derived> |
| 5536 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5537 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5538 | // Transform arguments. |
| 5539 | bool ArgChanged = false; |
| 5540 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5541 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5542 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5543 | if (Arg.isInvalid()) |
| 5544 | return SemaRef.ExprError(); |
| 5545 | |
| 5546 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5547 | Args.push_back(Arg.takeAs<Expr>()); |
| 5548 | } |
| 5549 | |
| 5550 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5551 | // Class message: transform the receiver type. |
| 5552 | TypeSourceInfo *ReceiverTypeInfo |
| 5553 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5554 | if (!ReceiverTypeInfo) |
| 5555 | return SemaRef.ExprError(); |
| 5556 | |
| 5557 | // If nothing changed, just retain the existing message send. |
| 5558 | if (!getDerived().AlwaysRebuild() && |
| 5559 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5560 | return SemaRef.Owned(E->Retain()); |
| 5561 | |
| 5562 | // Build a new class message send. |
| 5563 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5564 | E->getSelector(), |
| 5565 | E->getMethodDecl(), |
| 5566 | E->getLeftLoc(), |
| 5567 | move_arg(Args), |
| 5568 | E->getRightLoc()); |
| 5569 | } |
| 5570 | |
| 5571 | // Instance message: transform the receiver |
| 5572 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5573 | "Only class and instance messages may be instantiated"); |
| 5574 | OwningExprResult Receiver |
| 5575 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5576 | if (Receiver.isInvalid()) |
| 5577 | return SemaRef.ExprError(); |
| 5578 | |
| 5579 | // If nothing changed, just retain the existing message send. |
| 5580 | if (!getDerived().AlwaysRebuild() && |
| 5581 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5582 | return SemaRef.Owned(E->Retain()); |
| 5583 | |
| 5584 | // Build a new instance message send. |
| 5585 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5586 | E->getSelector(), |
| 5587 | E->getMethodDecl(), |
| 5588 | E->getLeftLoc(), |
| 5589 | move_arg(Args), |
| 5590 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | } |
| 5592 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | template<typename Derived> |
| 5594 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5595 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5597 | } |
| 5598 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5599 | template<typename Derived> |
| 5600 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5601 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5602 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5603 | = cast_or_null<ObjCProtocolDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5604 | getDerived().TransformDecl(E->getLocStart(), |
| 5605 | E->getProtocol())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | if (!Protocol) |
| 5607 | return SemaRef.ExprError(); |
| 5608 | |
| 5609 | if (!getDerived().AlwaysRebuild() && |
| 5610 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | return SemaRef.Owned(E->Retain()); |
| 5612 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5613 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5614 | E->getAtLoc(), |
| 5615 | /*FIXME:*/E->getAtLoc(), |
| 5616 | /*FIXME:*/E->getAtLoc(), |
| 5617 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5619 | } |
| 5620 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5621 | template<typename Derived> |
| 5622 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5623 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5624 | // FIXME: Implement this! |
| 5625 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5626 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5627 | } |
| 5628 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5629 | template<typename Derived> |
| 5630 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5631 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5632 | // FIXME: Implement this! |
| 5633 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5635 | } |
| 5636 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | template<typename Derived> |
| 5638 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5639 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5640 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5641 | // FIXME: Implement this! |
| 5642 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | } |
| 5645 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5646 | template<typename Derived> |
| 5647 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5648 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5649 | // FIXME: Implement this! |
| 5650 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5651 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5654 | template<typename Derived> |
| 5655 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5656 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5657 | // FIXME: Implement this! |
| 5658 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5659 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | template<typename Derived> |
| 5663 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5664 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5665 | bool ArgumentChanged = false; |
| 5666 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5667 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5668 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5669 | if (SubExpr.isInvalid()) |
| 5670 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5672 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5673 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5676 | if (!getDerived().AlwaysRebuild() && |
| 5677 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | return SemaRef.Owned(E->Retain()); |
| 5679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5680 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5681 | move_arg(SubExprs), |
| 5682 | E->getRParenLoc()); |
| 5683 | } |
| 5684 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | template<typename Derived> |
| 5686 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5687 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5688 | // FIXME: Implement this! |
| 5689 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5690 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5691 | } |
| 5692 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | template<typename Derived> |
| 5694 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5695 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5696 | // FIXME: Implement this! |
| 5697 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5698 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5699 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5700 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5701 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5702 | // Type reconstruction |
| 5703 | //===----------------------------------------------------------------------===// |
| 5704 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5705 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5706 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5707 | SourceLocation Star) { |
| 5708 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5709 | getDerived().getBaseEntity()); |
| 5710 | } |
| 5711 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5712 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5713 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5714 | SourceLocation Star) { |
| 5715 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5716 | getDerived().getBaseEntity()); |
| 5717 | } |
| 5718 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5719 | template<typename Derived> |
| 5720 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5721 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5722 | bool WrittenAsLValue, |
| 5723 | SourceLocation Sigil) { |
| 5724 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5725 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5730 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5731 | QualType ClassType, |
| 5732 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5733 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5734 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5738 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5739 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5740 | ArrayType::ArraySizeModifier SizeMod, |
| 5741 | const llvm::APInt *Size, |
| 5742 | Expr *SizeExpr, |
| 5743 | unsigned IndexTypeQuals, |
| 5744 | SourceRange BracketsRange) { |
| 5745 | if (SizeExpr || !Size) |
| 5746 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5747 | IndexTypeQuals, BracketsRange, |
| 5748 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5749 | |
| 5750 | QualType Types[] = { |
| 5751 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5752 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5753 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5754 | }; |
| 5755 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5756 | QualType SizeType; |
| 5757 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5758 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5759 | SizeType = Types[I]; |
| 5760 | break; |
| 5761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5762 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5763 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5764 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5765 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5766 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5768 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5769 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5770 | QualType |
| 5771 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5772 | ArrayType::ArraySizeModifier SizeMod, |
| 5773 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5774 | unsigned IndexTypeQuals, |
| 5775 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5776 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5777 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5781 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5782 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5783 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5784 | unsigned IndexTypeQuals, |
| 5785 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5786 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5787 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5789 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5790 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5791 | QualType |
| 5792 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5793 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5794 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5795 | unsigned IndexTypeQuals, |
| 5796 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5797 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5798 | SizeExpr.takeAs<Expr>(), |
| 5799 | IndexTypeQuals, BracketsRange); |
| 5800 | } |
| 5801 | |
| 5802 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5803 | QualType |
| 5804 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5805 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5806 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5807 | unsigned IndexTypeQuals, |
| 5808 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5809 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5810 | SizeExpr.takeAs<Expr>(), |
| 5811 | IndexTypeQuals, BracketsRange); |
| 5812 | } |
| 5813 | |
| 5814 | template<typename Derived> |
| 5815 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5816 | unsigned NumElements, |
| 5817 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5818 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5819 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5820 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5821 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5822 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5823 | template<typename Derived> |
| 5824 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5825 | unsigned NumElements, |
| 5826 | SourceLocation AttributeLoc) { |
| 5827 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5828 | NumElements, true); |
| 5829 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5830 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5831 | AttributeLoc); |
| 5832 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5833 | AttributeLoc); |
| 5834 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5835 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5836 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5837 | QualType |
| 5838 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5839 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5840 | SourceLocation AttributeLoc) { |
| 5841 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5843 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5844 | template<typename Derived> |
| 5845 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5846 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5847 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5848 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5849 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5850 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5851 | Quals, |
| 5852 | getDerived().getBaseLocation(), |
| 5853 | getDerived().getBaseEntity()); |
| 5854 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5855 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5856 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5857 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5858 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5859 | } |
| 5860 | |
| 5861 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5862 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5863 | assert(D && "no decl found"); |
| 5864 | if (D->isInvalidDecl()) return QualType(); |
| 5865 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5866 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5867 | TypeDecl *Ty; |
| 5868 | if (isa<UsingDecl>(D)) { |
| 5869 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5870 | assert(Using->isTypeName() && |
| 5871 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5872 | |
| 5873 | // A valid resolved using typename decl points to exactly one type decl. |
| 5874 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5875 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5876 | |
| 5877 | } else { |
| 5878 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5879 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5880 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5881 | } |
| 5882 | |
| 5883 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5884 | } |
| 5885 | |
| 5886 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5887 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5888 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5889 | } |
| 5890 | |
| 5891 | template<typename Derived> |
| 5892 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5893 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5894 | } |
| 5895 | |
| 5896 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5897 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5898 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5899 | } |
| 5900 | |
| 5901 | template<typename Derived> |
| 5902 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5903 | TemplateName Template, |
| 5904 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5905 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5906 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5907 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5908 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5909 | template<typename Derived> |
| 5910 | NestedNameSpecifier * |
| 5911 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5912 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5913 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5914 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5915 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5916 | CXXScopeSpec SS; |
| 5917 | // FIXME: The source location information is all wrong. |
| 5918 | SS.setRange(Range); |
| 5919 | SS.setScopeRep(Prefix); |
| 5920 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5921 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5922 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5923 | ObjectType, |
| 5924 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5925 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | template<typename Derived> |
| 5929 | NestedNameSpecifier * |
| 5930 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5931 | SourceRange Range, |
| 5932 | NamespaceDecl *NS) { |
| 5933 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5934 | } |
| 5935 | |
| 5936 | template<typename Derived> |
| 5937 | NestedNameSpecifier * |
| 5938 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5939 | SourceRange Range, |
| 5940 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5941 | QualType T) { |
| 5942 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5943 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5944 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5945 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5946 | T.getTypePtr()); |
| 5947 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5948 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5949 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5950 | return 0; |
| 5951 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5952 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5953 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5954 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5955 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5956 | bool TemplateKW, |
| 5957 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5958 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5959 | Template); |
| 5960 | } |
| 5961 | |
| 5962 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5963 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5964 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5965 | const IdentifierInfo &II, |
| 5966 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5967 | CXXScopeSpec SS; |
| 5968 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5969 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5970 | UnqualifiedId Name; |
| 5971 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5972 | return getSema().ActOnDependentTemplateName( |
| 5973 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5974 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5975 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5976 | ObjectType.getAsOpaquePtr(), |
| 5977 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5978 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5979 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5980 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5981 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5982 | TemplateName |
| 5983 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5984 | OverloadedOperatorKind Operator, |
| 5985 | QualType ObjectType) { |
| 5986 | CXXScopeSpec SS; |
| 5987 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5988 | SS.setScopeRep(Qualifier); |
| 5989 | UnqualifiedId Name; |
| 5990 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5991 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5992 | Operator, SymbolLocations); |
| 5993 | return getSema().ActOnDependentTemplateName( |
| 5994 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5995 | SS, |
| 5996 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5997 | ObjectType.getAsOpaquePtr(), |
| 5998 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5999 | .template getAsVal<TemplateName>(); |
| 6000 | } |
| 6001 | |
| 6002 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6003 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6004 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6005 | SourceLocation OpLoc, |
| 6006 | ExprArg Callee, |
| 6007 | ExprArg First, |
| 6008 | ExprArg Second) { |
| 6009 | Expr *FirstExpr = (Expr *)First.get(); |
| 6010 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6011 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6012 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6013 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6014 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6015 | if (Op == OO_Subscript) { |
| 6016 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6017 | !SecondExpr->getType()->isOverloadableType()) |
| 6018 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6019 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6020 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6021 | } else if (Op == OO_Arrow) { |
| 6022 | // -> is never a builtin operation. |
| 6023 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6024 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6025 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6026 | // The argument is not of overloadable type, so try to create a |
| 6027 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6028 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6029 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6030 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6032 | } |
| 6033 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6034 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6035 | !SecondExpr->getType()->isOverloadableType()) { |
| 6036 | // Neither of the arguments is an overloadable type, so try to |
| 6037 | // create a built-in binary operation. |
| 6038 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6039 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6040 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6041 | if (Result.isInvalid()) |
| 6042 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6043 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6044 | First.release(); |
| 6045 | Second.release(); |
| 6046 | return move(Result); |
| 6047 | } |
| 6048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6049 | |
| 6050 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6051 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6052 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6053 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6054 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6055 | assert(ULE->requiresADL()); |
| 6056 | |
| 6057 | // FIXME: Do we have to check |
| 6058 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6059 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6060 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6061 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6063 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6064 | // Add any functions found via argument-dependent lookup. |
| 6065 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6066 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6068 | // Create the overloaded operator invocation for unary operators. |
| 6069 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6070 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6071 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6072 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6074 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6075 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6076 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6077 | OpLoc, |
| 6078 | move(First), |
| 6079 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6080 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6081 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6083 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6084 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6085 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6086 | if (Result.isInvalid()) |
| 6087 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6089 | First.release(); |
| 6090 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6091 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6092 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6093 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6094 | template<typename Derived> |
| 6095 | Sema::OwningExprResult |
| 6096 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6097 | SourceLocation OperatorLoc, |
| 6098 | bool isArrow, |
| 6099 | NestedNameSpecifier *Qualifier, |
| 6100 | SourceRange QualifierRange, |
| 6101 | TypeSourceInfo *ScopeType, |
| 6102 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6103 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6104 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6105 | CXXScopeSpec SS; |
| 6106 | if (Qualifier) { |
| 6107 | SS.setRange(QualifierRange); |
| 6108 | SS.setScopeRep(Qualifier); |
| 6109 | } |
| 6110 | |
| 6111 | Expr *BaseE = (Expr *)Base.get(); |
| 6112 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6113 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6114 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 6115 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6116 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6117 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6118 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6119 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6120 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6121 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6122 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6123 | /*FIXME?*/true); |
| 6124 | } |
| 6125 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6126 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6127 | DeclarationName Name |
| 6128 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6129 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 6130 | |
| 6131 | // FIXME: the ScopeType should be tacked onto SS. |
| 6132 | |
| 6133 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6134 | OperatorLoc, isArrow, |
| 6135 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6136 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6137 | /*TemplateArgs*/ 0); |
| 6138 | } |
| 6139 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6140 | } // end namespace clang |
| 6141 | |
| 6142 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |