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. |
| 240 | Decl *TransformDecl(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. |
| 246 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 248 | /// \brief Transform the given declaration, which was the first part of a |
| 249 | /// nested-name-specifier in a member access expression. |
| 250 | /// |
| 251 | /// This specific declaration transformation only applies to the first |
| 252 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 253 | /// the \c T in \c x->T::member |
| 254 | /// |
| 255 | /// By default, invokes TransformDecl() to transform the declaration. |
| 256 | /// Subclasses may override this function to provide alternate behavior. |
| 257 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 258 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 259 | } |
| 260 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 261 | /// \brief Transform the given nested-name-specifier. |
| 262 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 264 | /// nested-name-specifier. Subclasses may override this function to provide |
| 265 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 266 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 267 | SourceRange Range, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 268 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 269 | QualType ObjectType = QualType(), |
| 270 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 272 | /// \brief Transform the given declaration name. |
| 273 | /// |
| 274 | /// By default, transforms the types of conversion function, constructor, |
| 275 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 276 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 277 | /// override this function to provide alternate behavior. |
| 278 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 279 | SourceLocation Loc, |
| 280 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 283 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 284 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 286 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 287 | TemplateName TransformTemplateName(TemplateName Name, |
| 288 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 290 | /// \brief Transform the given template argument. |
| 291 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | /// By default, this operation transforms the type, expression, or |
| 293 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 294 | /// new template argument from the transformed result. Subclasses may |
| 295 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 296 | /// |
| 297 | /// Returns true if there was an error. |
| 298 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 299 | TemplateArgumentLoc &Output); |
| 300 | |
| 301 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 302 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 303 | TemplateArgumentLoc &ArgLoc); |
| 304 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 305 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 306 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 307 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 308 | getDerived().getBaseLocation()); |
| 309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 311 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 312 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 313 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 314 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 315 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 316 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 317 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 318 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 319 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 320 | QualType |
| 321 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 322 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | #define STMT(Node, Parent) \ |
| 327 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 328 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 329 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define ABSTRACT_EXPR(Node, Parent) |
| 331 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 333 | /// \brief Build a new pointer type given its pointee type. |
| 334 | /// |
| 335 | /// By default, performs semantic analysis when building the pointer type. |
| 336 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 337 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | |
| 339 | /// \brief Build a new block pointer type given its pointee type. |
| 340 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 342 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 343 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// By default, performs semantic analysis when building the |
| 348 | /// reference type. Subclasses may override this routine to provide |
| 349 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 351 | /// \param LValue whether the type was written with an lvalue sigil |
| 352 | /// or an rvalue sigil. |
| 353 | QualType RebuildReferenceType(QualType ReferentType, |
| 354 | bool LValue, |
| 355 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 357 | /// \brief Build a new member pointer type given the pointee type and the |
| 358 | /// class type it refers into. |
| 359 | /// |
| 360 | /// By default, performs semantic analysis when building the member pointer |
| 361 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 363 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 365 | /// \brief Build a new Objective C object pointer type. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 366 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 367 | SourceLocation Sigil); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 369 | /// \brief Build a new array type given the element type, size |
| 370 | /// modifier, size of the array (if known), size expression, and index type |
| 371 | /// qualifiers. |
| 372 | /// |
| 373 | /// By default, performs semantic analysis when building the array type. |
| 374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | QualType RebuildArrayType(QualType ElementType, |
| 377 | ArrayType::ArraySizeModifier SizeMod, |
| 378 | const llvm::APInt *Size, |
| 379 | Expr *SizeExpr, |
| 380 | unsigned IndexTypeQuals, |
| 381 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | /// \brief Build a new constant array type given the element type, size |
| 384 | /// modifier, (known) size of the array, and index type qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 391 | unsigned IndexTypeQuals, |
| 392 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | /// \brief Build a new incomplete array type given the element type, size |
| 395 | /// modifier, and index type qualifiers. |
| 396 | /// |
| 397 | /// By default, performs semantic analysis when building the array type. |
| 398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 400 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 401 | unsigned IndexTypeQuals, |
| 402 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 403 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// size modifier, size expression, and index type qualifiers. |
| 406 | /// |
| 407 | /// By default, performs semantic analysis when building the array type. |
| 408 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | unsigned IndexTypeQuals, |
| 413 | SourceRange BracketsRange); |
| 414 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | /// size modifier, size expression, and index type qualifiers. |
| 417 | /// |
| 418 | /// By default, performs semantic analysis when building the array type. |
| 419 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | unsigned IndexTypeQuals, |
| 424 | SourceRange BracketsRange); |
| 425 | |
| 426 | /// \brief Build a new vector type given the element type and |
| 427 | /// number of elements. |
| 428 | /// |
| 429 | /// By default, performs semantic analysis when building the vector type. |
| 430 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 432 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | /// \brief Build a new extended vector type given the element type and |
| 435 | /// number of elements. |
| 436 | /// |
| 437 | /// By default, performs semantic analysis when building the vector type. |
| 438 | /// Subclasses may override this routine to provide different behavior. |
| 439 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 440 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | |
| 442 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 443 | /// given the element type and number of elements. |
| 444 | /// |
| 445 | /// By default, performs semantic analysis when building the vector type. |
| 446 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 448 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 449 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 451 | /// \brief Build a new function type. |
| 452 | /// |
| 453 | /// By default, performs semantic analysis when building the function type. |
| 454 | /// Subclasses may override this routine to provide different behavior. |
| 455 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 457 | unsigned NumParamTypes, |
| 458 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 459 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 460 | /// \brief Build a new unprototyped function type. |
| 461 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 462 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 463 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 464 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 465 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 466 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 467 | /// \brief Build a new typedef type. |
| 468 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 469 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 470 | } |
| 471 | |
| 472 | /// \brief Build a new class/struct/union type. |
| 473 | QualType RebuildRecordType(RecordDecl *Record) { |
| 474 | return SemaRef.Context.getTypeDeclType(Record); |
| 475 | } |
| 476 | |
| 477 | /// \brief Build a new Enum type. |
| 478 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 479 | return SemaRef.Context.getTypeDeclType(Enum); |
| 480 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 481 | |
| 482 | /// \brief Build a new elaborated type. |
| 483 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 484 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 485 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
| 487 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 488 | /// |
| 489 | /// By default, performs semantic analysis when building the typeof type. |
| 490 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 491 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 492 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 494 | /// |
| 495 | /// By default, builds a new TypeOfType with the given underlying type. |
| 496 | QualType RebuildTypeOfType(QualType Underlying); |
| 497 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 499 | /// |
| 500 | /// By default, performs semantic analysis when building the decltype type. |
| 501 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 502 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 504 | /// \brief Build a new template specialization type. |
| 505 | /// |
| 506 | /// By default, performs semantic analysis when building the template |
| 507 | /// specialization type. Subclasses may override this routine to provide |
| 508 | /// different behavior. |
| 509 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 510 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 511 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 513 | /// \brief Build a new qualified name type. |
| 514 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | /// By default, builds a new QualifiedNameType type from the |
| 516 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// this routine to provide different behavior. |
| 518 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 519 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | |
| 522 | /// \brief Build a new typename type that refers to a template-id. |
| 523 | /// |
| 524 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// different behavior. |
| 527 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 528 | if (NNS->isDependent()) { |
| 529 | CXXScopeSpec SS; |
| 530 | SS.setScopeRep(NNS); |
| 531 | if (!SemaRef.computeDeclContext(SS)) |
| 532 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 538 | |
| 539 | /// \brief Build a new typename type that refers to an identifier. |
| 540 | /// |
| 541 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 543 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 545 | const IdentifierInfo *Id, |
| 546 | SourceRange SR) { |
| 547 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 550 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 551 | /// identifier that names the next step in the nested-name-specifier. |
| 552 | /// |
| 553 | /// By default, performs semantic analysis when building the new |
| 554 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 555 | /// different behavior. |
| 556 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 557 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 558 | IdentifierInfo &II, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 559 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 560 | QualType ObjectType, |
| 561 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 562 | |
| 563 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 564 | /// namespace named in the next step in the nested-name-specifier. |
| 565 | /// |
| 566 | /// By default, performs semantic analysis when building the new |
| 567 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 568 | /// different behavior. |
| 569 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 570 | SourceRange Range, |
| 571 | NamespaceDecl *NS); |
| 572 | |
| 573 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 574 | /// type named in the next step in the nested-name-specifier. |
| 575 | /// |
| 576 | /// By default, performs semantic analysis when building the new |
| 577 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 578 | /// different behavior. |
| 579 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 580 | SourceRange Range, |
| 581 | bool TemplateKW, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 582 | QualType T, |
| 583 | bool MayBePseudoDestructor); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 584 | |
| 585 | /// \brief Build a new template name given a nested name specifier, a flag |
| 586 | /// indicating whether the "template" keyword was provided, and the template |
| 587 | /// that the template name refers to. |
| 588 | /// |
| 589 | /// By default, builds the new template name directly. Subclasses may override |
| 590 | /// this routine to provide different behavior. |
| 591 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 592 | bool TemplateKW, |
| 593 | TemplateDecl *Template); |
| 594 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 595 | /// \brief Build a new template name given a nested name specifier and the |
| 596 | /// name that is referred to as a template. |
| 597 | /// |
| 598 | /// By default, performs semantic analysis to determine whether the name can |
| 599 | /// be resolved to a specific template, then builds the appropriate kind of |
| 600 | /// template name. Subclasses may override this routine to provide different |
| 601 | /// behavior. |
| 602 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 603 | const IdentifierInfo &II, |
| 604 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 606 | /// \brief Build a new template name given a nested name specifier and the |
| 607 | /// overloaded operator name that is referred to as a template. |
| 608 | /// |
| 609 | /// By default, performs semantic analysis to determine whether the name can |
| 610 | /// be resolved to a specific template, then builds the appropriate kind of |
| 611 | /// template name. Subclasses may override this routine to provide different |
| 612 | /// behavior. |
| 613 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 614 | OverloadedOperatorKind Operator, |
| 615 | QualType ObjectType); |
| 616 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 617 | /// \brief Build a new compound statement. |
| 618 | /// |
| 619 | /// By default, performs semantic analysis to build the new statement. |
| 620 | /// Subclasses may override this routine to provide different behavior. |
| 621 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 622 | MultiStmtArg Statements, |
| 623 | SourceLocation RBraceLoc, |
| 624 | bool IsStmtExpr) { |
| 625 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 626 | IsStmtExpr); |
| 627 | } |
| 628 | |
| 629 | /// \brief Build a new case statement. |
| 630 | /// |
| 631 | /// By default, performs semantic analysis to build the new statement. |
| 632 | /// Subclasses may override this routine to provide different behavior. |
| 633 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 634 | ExprArg LHS, |
| 635 | SourceLocation EllipsisLoc, |
| 636 | ExprArg RHS, |
| 637 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 639 | ColonLoc); |
| 640 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 642 | /// \brief Attach the body to a new case statement. |
| 643 | /// |
| 644 | /// By default, performs semantic analysis to build the new statement. |
| 645 | /// Subclasses may override this routine to provide different behavior. |
| 646 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 647 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 648 | return move(S); |
| 649 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 651 | /// \brief Build a new default statement. |
| 652 | /// |
| 653 | /// By default, performs semantic analysis to build the new statement. |
| 654 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 656 | SourceLocation ColonLoc, |
| 657 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 659 | /*CurScope=*/0); |
| 660 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 662 | /// \brief Build a new label statement. |
| 663 | /// |
| 664 | /// By default, performs semantic analysis to build the new statement. |
| 665 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 667 | IdentifierInfo *Id, |
| 668 | SourceLocation ColonLoc, |
| 669 | StmtArg SubStmt) { |
| 670 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 673 | /// \brief Build a new "if" statement. |
| 674 | /// |
| 675 | /// By default, performs semantic analysis to build the new statement. |
| 676 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 678 | VarDecl *CondVar, StmtArg Then, |
| 679 | SourceLocation ElseLoc, StmtArg Else) { |
| 680 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 681 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 682 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 684 | /// \brief Start building a new switch statement. |
| 685 | /// |
| 686 | /// By default, performs semantic analysis to build the new statement. |
| 687 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 688 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 689 | VarDecl *CondVar) { |
| 690 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 693 | /// \brief Attach the body to the switch statement. |
| 694 | /// |
| 695 | /// By default, performs semantic analysis to build the new statement. |
| 696 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 698 | StmtArg Switch, StmtArg Body) { |
| 699 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 700 | move(Body)); |
| 701 | } |
| 702 | |
| 703 | /// \brief Build a new while statement. |
| 704 | /// |
| 705 | /// By default, performs semantic analysis to build the new statement. |
| 706 | /// Subclasses may override this routine to provide different behavior. |
| 707 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 708 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 709 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 710 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 711 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 712 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 713 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 715 | /// \brief Build a new do-while statement. |
| 716 | /// |
| 717 | /// By default, performs semantic analysis to build the new statement. |
| 718 | /// Subclasses may override this routine to provide different behavior. |
| 719 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 720 | SourceLocation WhileLoc, |
| 721 | SourceLocation LParenLoc, |
| 722 | ExprArg Cond, |
| 723 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 725 | move(Cond), RParenLoc); |
| 726 | } |
| 727 | |
| 728 | /// \brief Build a new for statement. |
| 729 | /// |
| 730 | /// By default, performs semantic analysis to build the new statement. |
| 731 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 734 | StmtArg Init, Sema::FullExprArg Cond, |
| 735 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 736 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 737 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 738 | DeclPtrTy::make(CondVar), |
| 739 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 742 | /// \brief Build a new goto statement. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis to build the new statement. |
| 745 | /// Subclasses may override this routine to provide different behavior. |
| 746 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 747 | SourceLocation LabelLoc, |
| 748 | LabelStmt *Label) { |
| 749 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 750 | } |
| 751 | |
| 752 | /// \brief Build a new indirect goto statement. |
| 753 | /// |
| 754 | /// By default, performs semantic analysis to build the new statement. |
| 755 | /// Subclasses may override this routine to provide different behavior. |
| 756 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 757 | SourceLocation StarLoc, |
| 758 | ExprArg Target) { |
| 759 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 762 | /// \brief Build a new return statement. |
| 763 | /// |
| 764 | /// By default, performs semantic analysis to build the new statement. |
| 765 | /// Subclasses may override this routine to provide different behavior. |
| 766 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 767 | ExprArg Result) { |
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 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 772 | /// \brief Build a new declaration statement. |
| 773 | /// |
| 774 | /// By default, performs semantic analysis to build the new statement. |
| 775 | /// Subclasses may override this routine to provide different behavior. |
| 776 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 778 | SourceLocation EndLoc) { |
| 779 | return getSema().Owned( |
| 780 | new (getSema().Context) DeclStmt( |
| 781 | DeclGroupRef::Create(getSema().Context, |
| 782 | Decls, NumDecls), |
| 783 | StartLoc, EndLoc)); |
| 784 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 786 | /// \brief Build a new inline asm statement. |
| 787 | /// |
| 788 | /// By default, performs semantic analysis to build the new statement. |
| 789 | /// Subclasses may override this routine to provide different behavior. |
| 790 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 791 | bool IsSimple, |
| 792 | bool IsVolatile, |
| 793 | unsigned NumOutputs, |
| 794 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 795 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 796 | MultiExprArg Constraints, |
| 797 | MultiExprArg Exprs, |
| 798 | ExprArg AsmString, |
| 799 | MultiExprArg Clobbers, |
| 800 | SourceLocation RParenLoc, |
| 801 | bool MSAsm) { |
| 802 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 803 | NumInputs, Names, move(Constraints), |
| 804 | move(Exprs), move(AsmString), move(Clobbers), |
| 805 | RParenLoc, MSAsm); |
| 806 | } |
| 807 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 808 | /// \brief Build a new C++ exception declaration. |
| 809 | /// |
| 810 | /// By default, performs semantic analysis to build the new decaration. |
| 811 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 813 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 814 | IdentifierInfo *Name, |
| 815 | SourceLocation Loc, |
| 816 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | TypeRange); |
| 819 | } |
| 820 | |
| 821 | /// \brief Build a new C++ catch statement. |
| 822 | /// |
| 823 | /// By default, performs semantic analysis to build the new statement. |
| 824 | /// Subclasses may override this routine to provide different behavior. |
| 825 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 826 | VarDecl *ExceptionDecl, |
| 827 | StmtArg Handler) { |
| 828 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 830 | Handler.takeAs<Stmt>())); |
| 831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 833 | /// \brief Build a new C++ try statement. |
| 834 | /// |
| 835 | /// By default, performs semantic analysis to build the new statement. |
| 836 | /// Subclasses may override this routine to provide different behavior. |
| 837 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 838 | StmtArg TryBlock, |
| 839 | MultiStmtArg Handlers) { |
| 840 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 843 | /// \brief Build a new expression that references a declaration. |
| 844 | /// |
| 845 | /// By default, performs semantic analysis to build the new expression. |
| 846 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 847 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 848 | LookupResult &R, |
| 849 | bool RequiresADL) { |
| 850 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 851 | } |
| 852 | |
| 853 | |
| 854 | /// \brief Build a new expression that references a declaration. |
| 855 | /// |
| 856 | /// By default, performs semantic analysis to build the new expression. |
| 857 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 858 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 859 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 860 | ValueDecl *VD, SourceLocation Loc, |
| 861 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 862 | CXXScopeSpec SS; |
| 863 | SS.setScopeRep(Qualifier); |
| 864 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 865 | |
| 866 | // FIXME: loses template args. |
| 867 | |
| 868 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 871 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 873 | /// By default, performs semantic analysis to build the new expression. |
| 874 | /// Subclasses may override this routine to provide different behavior. |
| 875 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 876 | SourceLocation RParen) { |
| 877 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 878 | } |
| 879 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 880 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 881 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 882 | /// By default, performs semantic analysis to build the new expression. |
| 883 | /// Subclasses may override this routine to provide different behavior. |
| 884 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 885 | SourceLocation OperatorLoc, |
| 886 | bool isArrow, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame^] | 887 | NestedNameSpecifier *Qualifier, |
| 888 | SourceRange QualifierRange, |
| 889 | TypeSourceInfo *ScopeType, |
| 890 | SourceLocation CCLoc, |
| 891 | TypeSourceInfo *DestroyedType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 893 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 895 | /// By default, performs semantic analysis to build the new expression. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
| 897 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 898 | UnaryOperator::Opcode Opc, |
| 899 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 900 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 901 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 903 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 904 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 905 | /// By default, performs semantic analysis to build the new expression. |
| 906 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 907 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 908 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 909 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 910 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 914 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | /// By default, performs semantic analysis to build the new expression. |
| 917 | /// Subclasses may override this routine to provide different behavior. |
| 918 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 919 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 920 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 921 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 922 | OpLoc, isSizeOf, R); |
| 923 | if (Result.isInvalid()) |
| 924 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | SubExpr.release(); |
| 927 | return move(Result); |
| 928 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 930 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 932 | /// By default, performs semantic analysis to build the new expression. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 935 | SourceLocation LBracketLoc, |
| 936 | ExprArg RHS, |
| 937 | SourceLocation RBracketLoc) { |
| 938 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 940 | RBracketLoc); |
| 941 | } |
| 942 | |
| 943 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | /// By default, performs semantic analysis to build the new expression. |
| 946 | /// Subclasses may override this routine to provide different behavior. |
| 947 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 948 | MultiExprArg Args, |
| 949 | SourceLocation *CommaLocs, |
| 950 | SourceLocation RParenLoc) { |
| 951 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 952 | move(Args), CommaLocs, RParenLoc); |
| 953 | } |
| 954 | |
| 955 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 956 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 957 | /// By default, performs semantic analysis to build the new expression. |
| 958 | /// Subclasses may override this routine to provide different behavior. |
| 959 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 961 | NestedNameSpecifier *Qualifier, |
| 962 | SourceRange QualifierRange, |
| 963 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 964 | ValueDecl *Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 965 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 966 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 967 | if (!Member->getDeclName()) { |
| 968 | // We have a reference to an unnamed field. |
| 969 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 971 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 972 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 973 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 974 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 976 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 977 | Member, MemberLoc, |
| 978 | cast<FieldDecl>(Member)->getType()); |
| 979 | return getSema().Owned(ME); |
| 980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 982 | CXXScopeSpec SS; |
| 983 | if (Qualifier) { |
| 984 | SS.setRange(QualifierRange); |
| 985 | SS.setScopeRep(Qualifier); |
| 986 | } |
| 987 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 988 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 989 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 990 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 991 | Sema::LookupMemberName); |
| 992 | R.addDecl(Member); |
| 993 | R.resolveKind(); |
| 994 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 995 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 996 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 997 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 998 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1001 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1003 | /// By default, performs semantic analysis to build the new expression. |
| 1004 | /// Subclasses may override this routine to provide different behavior. |
| 1005 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1006 | BinaryOperator::Opcode Opc, |
| 1007 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1008 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1009 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | /// By default, performs semantic analysis to build the new expression. |
| 1015 | /// Subclasses may override this routine to provide different behavior. |
| 1016 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1017 | SourceLocation QuestionLoc, |
| 1018 | ExprArg LHS, |
| 1019 | SourceLocation ColonLoc, |
| 1020 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1021 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1022 | move(LHS), move(RHS)); |
| 1023 | } |
| 1024 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1027 | /// By default, performs semantic analysis to build the new expression. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1029 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1030 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1031 | SourceLocation RParenLoc, |
| 1032 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1033 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1034 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
| 1041 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1042 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1043 | SourceLocation RParenLoc, |
| 1044 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1045 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1046 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1051 | /// By default, performs semantic analysis to build the new expression. |
| 1052 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | SourceLocation OpLoc, |
| 1055 | SourceLocation AccessorLoc, |
| 1056 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1057 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1058 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1059 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1060 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1061 | OpLoc, /*IsArrow*/ false, |
| 1062 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1063 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1064 | AccessorLoc, |
| 1065 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | /// By default, performs semantic analysis to build the new expression. |
| 1071 | /// Subclasses may override this routine to provide different behavior. |
| 1072 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1073 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1074 | SourceLocation RBraceLoc, |
| 1075 | QualType ResultTy) { |
| 1076 | OwningExprResult Result |
| 1077 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1078 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1079 | return move(Result); |
| 1080 | |
| 1081 | // Patch in the result type we were given, which may have been computed |
| 1082 | // when the initial InitListExpr was built. |
| 1083 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1084 | ILE->setType(ResultTy); |
| 1085 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1086 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1088 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1089 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1090 | /// By default, performs semantic analysis to build the new expression. |
| 1091 | /// Subclasses may override this routine to provide different behavior. |
| 1092 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1093 | MultiExprArg ArrayExprs, |
| 1094 | SourceLocation EqualOrColonLoc, |
| 1095 | bool GNUSyntax, |
| 1096 | ExprArg Init) { |
| 1097 | OwningExprResult Result |
| 1098 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1099 | move(Init)); |
| 1100 | if (Result.isInvalid()) |
| 1101 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | ArrayExprs.release(); |
| 1104 | return move(Result); |
| 1105 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1107 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | /// By default, builds the implicit value initialization without performing |
| 1110 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1111 | /// different behavior. |
| 1112 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1113 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1116 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | /// By default, performs semantic analysis to build the new expression. |
| 1119 | /// Subclasses may override this routine to provide different behavior. |
| 1120 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1121 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1123 | RParenLoc); |
| 1124 | } |
| 1125 | |
| 1126 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// By default, performs semantic analysis to build the new expression. |
| 1129 | /// Subclasses may override this routine to provide different behavior. |
| 1130 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1131 | MultiExprArg SubExprs, |
| 1132 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1133 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1134 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1137 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | /// |
| 1139 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1140 | /// rather than attempting to map the label statement itself. |
| 1141 | /// Subclasses may override this routine to provide different behavior. |
| 1142 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1143 | SourceLocation LabelLoc, |
| 1144 | LabelStmt *Label) { |
| 1145 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1148 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1150 | /// By default, performs semantic analysis to build the new expression. |
| 1151 | /// Subclasses may override this routine to provide different behavior. |
| 1152 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1153 | StmtArg SubStmt, |
| 1154 | SourceLocation RParenLoc) { |
| 1155 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 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 __builtin_types_compatible_p expression. |
| 1159 | /// |
| 1160 | /// By default, performs semantic analysis to build the new expression. |
| 1161 | /// Subclasses may override this routine to provide different behavior. |
| 1162 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1163 | QualType T1, QualType T2, |
| 1164 | SourceLocation RParenLoc) { |
| 1165 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1166 | T1.getAsOpaquePtr(), |
| 1167 | T2.getAsOpaquePtr(), |
| 1168 | RParenLoc); |
| 1169 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1171 | /// \brief Build a new __builtin_choose_expr expression. |
| 1172 | /// |
| 1173 | /// By default, performs semantic analysis to build the new expression. |
| 1174 | /// Subclasses may override this routine to provide different behavior. |
| 1175 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1176 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1177 | SourceLocation RParenLoc) { |
| 1178 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1179 | move(Cond), move(LHS), move(RHS), |
| 1180 | RParenLoc); |
| 1181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1183 | /// \brief Build a new overloaded operator call expression. |
| 1184 | /// |
| 1185 | /// By default, performs semantic analysis to build the new expression. |
| 1186 | /// The semantic analysis provides the behavior of template instantiation, |
| 1187 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1188 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1189 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1190 | /// provide different behavior. |
| 1191 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1192 | SourceLocation OpLoc, |
| 1193 | ExprArg Callee, |
| 1194 | ExprArg First, |
| 1195 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | |
| 1197 | /// \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] | 1198 | /// reinterpret_cast. |
| 1199 | /// |
| 1200 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | /// Subclasses may override this routine to provide different behavior. |
| 1203 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1204 | Stmt::StmtClass Class, |
| 1205 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1206 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1207 | SourceLocation RAngleLoc, |
| 1208 | SourceLocation LParenLoc, |
| 1209 | ExprArg SubExpr, |
| 1210 | SourceLocation RParenLoc) { |
| 1211 | switch (Class) { |
| 1212 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1213 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | move(SubExpr), RParenLoc); |
| 1216 | |
| 1217 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1218 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1223 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | RAngleLoc, LParenLoc, |
| 1225 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1229 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1231 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1232 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1233 | default: |
| 1234 | assert(false && "Invalid C++ named cast"); |
| 1235 | break; |
| 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 | return getSema().ExprError(); |
| 1239 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | /// \brief Build a new C++ static_cast expression. |
| 1242 | /// |
| 1243 | /// By default, performs semantic analysis to build the new expression. |
| 1244 | /// Subclasses may override this routine to provide different behavior. |
| 1245 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1246 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1247 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1248 | SourceLocation RAngleLoc, |
| 1249 | SourceLocation LParenLoc, |
| 1250 | ExprArg SubExpr, |
| 1251 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1252 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1253 | TInfo, move(SubExpr), |
| 1254 | SourceRange(LAngleLoc, RAngleLoc), |
| 1255 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /// \brief Build a new C++ dynamic_cast expression. |
| 1259 | /// |
| 1260 | /// By default, performs semantic analysis to build the new expression. |
| 1261 | /// Subclasses may override this routine to provide different behavior. |
| 1262 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1263 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1264 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1265 | SourceLocation RAngleLoc, |
| 1266 | SourceLocation LParenLoc, |
| 1267 | ExprArg SubExpr, |
| 1268 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1269 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1270 | TInfo, move(SubExpr), |
| 1271 | SourceRange(LAngleLoc, RAngleLoc), |
| 1272 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1276 | /// |
| 1277 | /// By default, performs semantic analysis to build the new expression. |
| 1278 | /// Subclasses may override this routine to provide different behavior. |
| 1279 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1280 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1281 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1282 | SourceLocation RAngleLoc, |
| 1283 | SourceLocation LParenLoc, |
| 1284 | ExprArg SubExpr, |
| 1285 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1286 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1287 | TInfo, move(SubExpr), |
| 1288 | SourceRange(LAngleLoc, RAngleLoc), |
| 1289 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /// \brief Build a new C++ const_cast expression. |
| 1293 | /// |
| 1294 | /// By default, performs semantic analysis to build the new expression. |
| 1295 | /// Subclasses may override this routine to provide different behavior. |
| 1296 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1297 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1298 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1299 | SourceLocation RAngleLoc, |
| 1300 | SourceLocation LParenLoc, |
| 1301 | ExprArg SubExpr, |
| 1302 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1303 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1304 | TInfo, move(SubExpr), |
| 1305 | SourceRange(LAngleLoc, RAngleLoc), |
| 1306 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | /// \brief Build a new C++ functional-style cast expression. |
| 1310 | /// |
| 1311 | /// By default, performs semantic analysis to build the new expression. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1314 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | SourceLocation LParenLoc, |
| 1316 | ExprArg SubExpr, |
| 1317 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1318 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1320 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1322 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | RParenLoc); |
| 1325 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1327 | /// \brief Build a new C++ typeid(type) expression. |
| 1328 | /// |
| 1329 | /// By default, performs semantic analysis to build the new expression. |
| 1330 | /// Subclasses may override this routine to provide different behavior. |
| 1331 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1332 | SourceLocation LParenLoc, |
| 1333 | QualType T, |
| 1334 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1336 | T.getAsOpaquePtr(), RParenLoc); |
| 1337 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | /// \brief Build a new C++ typeid(expr) expression. |
| 1340 | /// |
| 1341 | /// By default, performs semantic analysis to build the new expression. |
| 1342 | /// Subclasses may override this routine to provide different behavior. |
| 1343 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1344 | SourceLocation LParenLoc, |
| 1345 | ExprArg Operand, |
| 1346 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1348 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1349 | RParenLoc); |
| 1350 | if (Result.isInvalid()) |
| 1351 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1354 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1357 | /// \brief Build a new C++ "this" expression. |
| 1358 | /// |
| 1359 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1360 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1361 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1363 | QualType ThisType, |
| 1364 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1366 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1367 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /// \brief Build a new C++ throw expression. |
| 1371 | /// |
| 1372 | /// By default, performs semantic analysis to build the new expression. |
| 1373 | /// Subclasses may override this routine to provide different behavior. |
| 1374 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1375 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1376 | } |
| 1377 | |
| 1378 | /// \brief Build a new C++ default-argument expression. |
| 1379 | /// |
| 1380 | /// By default, builds a new default-argument expression, which does not |
| 1381 | /// require any semantic analysis. Subclasses may override this routine to |
| 1382 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1383 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1384 | ParmVarDecl *Param) { |
| 1385 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1386 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /// \brief Build a new C++ zero-initialization expression. |
| 1390 | /// |
| 1391 | /// By default, performs semantic analysis to build the new expression. |
| 1392 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1394 | SourceLocation LParenLoc, |
| 1395 | QualType T, |
| 1396 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1398 | T.getAsOpaquePtr(), LParenLoc, |
| 1399 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | 0, RParenLoc); |
| 1401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | /// \brief Build a new C++ "new" expression. |
| 1404 | /// |
| 1405 | /// By default, performs semantic analysis to build the new expression. |
| 1406 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | bool UseGlobal, |
| 1409 | SourceLocation PlacementLParen, |
| 1410 | MultiExprArg PlacementArgs, |
| 1411 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | QualType AllocType, |
| 1414 | SourceLocation TypeLoc, |
| 1415 | SourceRange TypeRange, |
| 1416 | ExprArg ArraySize, |
| 1417 | SourceLocation ConstructorLParen, |
| 1418 | MultiExprArg ConstructorArgs, |
| 1419 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1421 | PlacementLParen, |
| 1422 | move(PlacementArgs), |
| 1423 | PlacementRParen, |
| 1424 | ParenTypeId, |
| 1425 | AllocType, |
| 1426 | TypeLoc, |
| 1427 | TypeRange, |
| 1428 | move(ArraySize), |
| 1429 | ConstructorLParen, |
| 1430 | move(ConstructorArgs), |
| 1431 | ConstructorRParen); |
| 1432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | /// \brief Build a new C++ "delete" expression. |
| 1435 | /// |
| 1436 | /// By default, performs semantic analysis to build the new expression. |
| 1437 | /// Subclasses may override this routine to provide different behavior. |
| 1438 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1439 | bool IsGlobalDelete, |
| 1440 | bool IsArrayForm, |
| 1441 | ExprArg Operand) { |
| 1442 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1443 | move(Operand)); |
| 1444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1446 | /// \brief Build a new unary type trait expression. |
| 1447 | /// |
| 1448 | /// By default, performs semantic analysis to build the new expression. |
| 1449 | /// Subclasses may override this routine to provide different behavior. |
| 1450 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1451 | SourceLocation StartLoc, |
| 1452 | SourceLocation LParenLoc, |
| 1453 | QualType T, |
| 1454 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1455 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | T.getAsOpaquePtr(), RParenLoc); |
| 1457 | } |
| 1458 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1459 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | /// expression. |
| 1461 | /// |
| 1462 | /// By default, performs semantic analysis to build the new expression. |
| 1463 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1464 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1465 | SourceRange QualifierRange, |
| 1466 | DeclarationName Name, |
| 1467 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1468 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | CXXScopeSpec SS; |
| 1470 | SS.setRange(QualifierRange); |
| 1471 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1472 | |
| 1473 | if (TemplateArgs) |
| 1474 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1475 | *TemplateArgs); |
| 1476 | |
| 1477 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | /// \brief Build a new template-id expression. |
| 1481 | /// |
| 1482 | /// By default, performs semantic analysis to build the new expression. |
| 1483 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1484 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1485 | LookupResult &R, |
| 1486 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1487 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1488 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /// \brief Build a new object-construction expression. |
| 1492 | /// |
| 1493 | /// By default, performs semantic analysis to build the new expression. |
| 1494 | /// Subclasses may override this routine to provide different behavior. |
| 1495 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1496 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1497 | CXXConstructorDecl *Constructor, |
| 1498 | bool IsElidable, |
| 1499 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1500 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1501 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1502 | ConvertedArgs)) |
| 1503 | return getSema().ExprError(); |
| 1504 | |
| 1505 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1506 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | /// \brief Build a new object-construction expression. |
| 1510 | /// |
| 1511 | /// By default, performs semantic analysis to build the new expression. |
| 1512 | /// Subclasses may override this routine to provide different behavior. |
| 1513 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1514 | QualType T, |
| 1515 | SourceLocation LParenLoc, |
| 1516 | MultiExprArg Args, |
| 1517 | SourceLocation *Commas, |
| 1518 | SourceLocation RParenLoc) { |
| 1519 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1520 | T.getAsOpaquePtr(), |
| 1521 | LParenLoc, |
| 1522 | move(Args), |
| 1523 | Commas, |
| 1524 | RParenLoc); |
| 1525 | } |
| 1526 | |
| 1527 | /// \brief Build a new object-construction expression. |
| 1528 | /// |
| 1529 | /// By default, performs semantic analysis to build the new expression. |
| 1530 | /// Subclasses may override this routine to provide different behavior. |
| 1531 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1532 | QualType T, |
| 1533 | SourceLocation LParenLoc, |
| 1534 | MultiExprArg Args, |
| 1535 | SourceLocation *Commas, |
| 1536 | SourceLocation RParenLoc) { |
| 1537 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1538 | /*FIXME*/LParenLoc), |
| 1539 | T.getAsOpaquePtr(), |
| 1540 | LParenLoc, |
| 1541 | move(Args), |
| 1542 | Commas, |
| 1543 | RParenLoc); |
| 1544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | /// \brief Build a new member reference expression. |
| 1547 | /// |
| 1548 | /// By default, performs semantic analysis to build the new expression. |
| 1549 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1550 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1551 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | bool IsArrow, |
| 1553 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1554 | NestedNameSpecifier *Qualifier, |
| 1555 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1556 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1558 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1559 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1561 | SS.setRange(QualifierRange); |
| 1562 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1564 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1565 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1566 | SS, FirstQualifierInScope, |
| 1567 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1570 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1571 | /// |
| 1572 | /// By default, performs semantic analysis to build the new expression. |
| 1573 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1574 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1575 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1576 | SourceLocation OperatorLoc, |
| 1577 | bool IsArrow, |
| 1578 | NestedNameSpecifier *Qualifier, |
| 1579 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1580 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1581 | LookupResult &R, |
| 1582 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1583 | CXXScopeSpec SS; |
| 1584 | SS.setRange(QualifierRange); |
| 1585 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1587 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1588 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1589 | SS, FirstQualifierInScope, |
| 1590 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | /// \brief Build a new Objective-C @encode expression. |
| 1594 | /// |
| 1595 | /// By default, performs semantic analysis to build the new expression. |
| 1596 | /// Subclasses may override this routine to provide different behavior. |
| 1597 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1598 | QualType T, |
| 1599 | SourceLocation RParenLoc) { |
| 1600 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1601 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1602 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1603 | |
| 1604 | /// \brief Build a new Objective-C protocol expression. |
| 1605 | /// |
| 1606 | /// By default, performs semantic analysis to build the new expression. |
| 1607 | /// Subclasses may override this routine to provide different behavior. |
| 1608 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1609 | SourceLocation AtLoc, |
| 1610 | SourceLocation ProtoLoc, |
| 1611 | SourceLocation LParenLoc, |
| 1612 | SourceLocation RParenLoc) { |
| 1613 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1614 | Protocol->getIdentifier(), |
| 1615 | AtLoc, |
| 1616 | ProtoLoc, |
| 1617 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1618 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1619 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1621 | /// \brief Build a new shuffle vector expression. |
| 1622 | /// |
| 1623 | /// By default, performs semantic analysis to build the new expression. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
| 1625 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1626 | MultiExprArg SubExprs, |
| 1627 | SourceLocation RParenLoc) { |
| 1628 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1631 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1632 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1633 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | // Build a reference to the __builtin_shufflevector builtin |
| 1636 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1638 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1639 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1640 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | |
| 1642 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | unsigned NumSubExprs = SubExprs.size(); |
| 1644 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1645 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1646 | Subs, NumSubExprs, |
| 1647 | Builtin->getResultType(), |
| 1648 | RParenLoc); |
| 1649 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1651 | // Type-check the __builtin_shufflevector expression. |
| 1652 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1653 | if (Result.isInvalid()) |
| 1654 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1659 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1661 | template<typename Derived> |
| 1662 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1663 | if (!S) |
| 1664 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1666 | switch (S->getStmtClass()) { |
| 1667 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1669 | // Transform individual statement nodes |
| 1670 | #define STMT(Node, Parent) \ |
| 1671 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1672 | #define EXPR(Node, Parent) |
| 1673 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1675 | // Transform expressions by calling TransformExpr. |
| 1676 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1677 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1678 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1679 | #include "clang/AST/StmtNodes.def" |
| 1680 | { |
| 1681 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1682 | if (E.isInvalid()) |
| 1683 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1685 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1686 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1689 | return SemaRef.Owned(S->Retain()); |
| 1690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | |
| 1692 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1693 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1694 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | if (!E) |
| 1696 | return SemaRef.Owned(E); |
| 1697 | |
| 1698 | switch (E->getStmtClass()) { |
| 1699 | case Stmt::NoStmtClass: break; |
| 1700 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1701 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1702 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1703 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1704 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1707 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1711 | NestedNameSpecifier * |
| 1712 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1713 | SourceRange Range, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1714 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1715 | QualType ObjectType, |
| 1716 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1717 | if (!NNS) |
| 1718 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1720 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1721 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1722 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1723 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1724 | false, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1725 | ObjectType, |
| 1726 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1727 | if (!Prefix) |
| 1728 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
| 1730 | // 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] | 1731 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1732 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1733 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1736 | switch (NNS->getKind()) { |
| 1737 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1738 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1739 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1740 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1741 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1742 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | |
| 1744 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1745 | *NNS->getAsIdentifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1746 | MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1747 | ObjectType, |
| 1748 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1750 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1752 | = cast_or_null<NamespaceDecl>( |
| 1753 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1755 | Prefix == NNS->getPrefix() && |
| 1756 | NS == NNS->getAsNamespace()) |
| 1757 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1759 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1762 | case NestedNameSpecifier::Global: |
| 1763 | // There is no meaningful transformation that one could perform on the |
| 1764 | // global scope. |
| 1765 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1768 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1769 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1770 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1771 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1772 | if (T.isNull()) |
| 1773 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1775 | if (!getDerived().AlwaysRebuild() && |
| 1776 | Prefix == NNS->getPrefix() && |
| 1777 | T == QualType(NNS->getAsType(), 0)) |
| 1778 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1779 | |
| 1780 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1781 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1782 | T, |
| 1783 | MayBePseudoDestructor); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1784 | } |
| 1785 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1787 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1788 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1793 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1794 | SourceLocation Loc, |
| 1795 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1796 | if (!Name) |
| 1797 | return Name; |
| 1798 | |
| 1799 | switch (Name.getNameKind()) { |
| 1800 | case DeclarationName::Identifier: |
| 1801 | case DeclarationName::ObjCZeroArgSelector: |
| 1802 | case DeclarationName::ObjCOneArgSelector: |
| 1803 | case DeclarationName::ObjCMultiArgSelector: |
| 1804 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1805 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | case DeclarationName::CXXUsingDirective: |
| 1807 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1809 | case DeclarationName::CXXConstructorName: |
| 1810 | case DeclarationName::CXXDestructorName: |
| 1811 | case DeclarationName::CXXConversionFunctionName: { |
| 1812 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1813 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1814 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1815 | if (T.isNull()) |
| 1816 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1817 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1818 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1820 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1821 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1824 | return DeclarationName(); |
| 1825 | } |
| 1826 | |
| 1827 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1828 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1829 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1830 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1831 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1833 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1834 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1835 | false, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1836 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1837 | if (!NNS) |
| 1838 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1840 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1841 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1842 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1843 | if (!TransTemplate) |
| 1844 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1846 | if (!getDerived().AlwaysRebuild() && |
| 1847 | NNS == QTN->getQualifier() && |
| 1848 | TransTemplate == Template) |
| 1849 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1851 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1852 | TransTemplate); |
| 1853 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1855 | // These should be getting filtered out before they make it into the AST. |
| 1856 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1857 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1859 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1861 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1862 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 1863 | false, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1864 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1865 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1866 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1869 | NNS == DTN->getQualifier() && |
| 1870 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1871 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1873 | if (DTN->isIdentifier()) |
| 1874 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1875 | ObjectType); |
| 1876 | |
| 1877 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1878 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1879 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1881 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1883 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1884 | if (!TransTemplate) |
| 1885 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1886 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1887 | if (!getDerived().AlwaysRebuild() && |
| 1888 | TransTemplate == Template) |
| 1889 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1890 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1891 | return TemplateName(TransTemplate); |
| 1892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1893 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1894 | // These should be getting filtered out before they reach the AST. |
| 1895 | assert(false && "overloaded function decl survived to here"); |
| 1896 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1900 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1901 | const TemplateArgument &Arg, |
| 1902 | TemplateArgumentLoc &Output) { |
| 1903 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1904 | switch (Arg.getKind()) { |
| 1905 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1906 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1907 | break; |
| 1908 | |
| 1909 | case TemplateArgument::Type: |
| 1910 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1911 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1912 | |
| 1913 | break; |
| 1914 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1915 | case TemplateArgument::Template: |
| 1916 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1917 | break; |
| 1918 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1919 | case TemplateArgument::Expression: |
| 1920 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1921 | break; |
| 1922 | |
| 1923 | case TemplateArgument::Declaration: |
| 1924 | case TemplateArgument::Integral: |
| 1925 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1926 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | template<typename Derived> |
| 1932 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1933 | const TemplateArgumentLoc &Input, |
| 1934 | TemplateArgumentLoc &Output) { |
| 1935 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1936 | switch (Arg.getKind()) { |
| 1937 | case TemplateArgument::Null: |
| 1938 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1939 | Output = Input; |
| 1940 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1941 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1942 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1943 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1944 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1945 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1946 | |
| 1947 | DI = getDerived().TransformType(DI); |
| 1948 | if (!DI) return true; |
| 1949 | |
| 1950 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1951 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1954 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1955 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1956 | DeclarationName Name; |
| 1957 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1958 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1959 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1960 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1961 | if (!D) return true; |
| 1962 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1963 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1964 | if (SourceExpr) { |
| 1965 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1966 | Action::Unevaluated); |
| 1967 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1968 | if (E.isInvalid()) |
| 1969 | SourceExpr = NULL; |
| 1970 | else { |
| 1971 | SourceExpr = E.takeAs<Expr>(); |
| 1972 | SourceExpr->Retain(); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1977 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1980 | case TemplateArgument::Template: { |
| 1981 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1982 | TemplateName Template |
| 1983 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1984 | if (Template.isNull()) |
| 1985 | return true; |
| 1986 | |
| 1987 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1988 | Input.getTemplateQualifierRange(), |
| 1989 | Input.getTemplateNameLoc()); |
| 1990 | return false; |
| 1991 | } |
| 1992 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1993 | case TemplateArgument::Expression: { |
| 1994 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1995 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1996 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1998 | Expr *InputExpr = Input.getSourceExpression(); |
| 1999 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2000 | |
| 2001 | Sema::OwningExprResult E |
| 2002 | = getDerived().TransformExpr(InputExpr); |
| 2003 | if (E.isInvalid()) return true; |
| 2004 | |
| 2005 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2006 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2007 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2008 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2009 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2010 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2011 | case TemplateArgument::Pack: { |
| 2012 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2013 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2014 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2015 | AEnd = Arg.pack_end(); |
| 2016 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2018 | // FIXME: preserve source information here when we start |
| 2019 | // caring about parameter packs. |
| 2020 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2021 | TemplateArgumentLoc InputArg; |
| 2022 | TemplateArgumentLoc OutputArg; |
| 2023 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2024 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2025 | return true; |
| 2026 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2027 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2028 | } |
| 2029 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2030 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2031 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2032 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2033 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2034 | } |
| 2035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2036 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2037 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2038 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2041 | //===----------------------------------------------------------------------===// |
| 2042 | // Type transformation |
| 2043 | //===----------------------------------------------------------------------===// |
| 2044 | |
| 2045 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2046 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2047 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2048 | if (getDerived().AlreadyTransformed(T)) |
| 2049 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2050 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2051 | // Temporary workaround. All of these transformations should |
| 2052 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2053 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2054 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2055 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2056 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2057 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2058 | if (!NewDI) |
| 2059 | return QualType(); |
| 2060 | |
| 2061 | return NewDI->getType(); |
| 2062 | } |
| 2063 | |
| 2064 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2065 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2066 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2067 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2068 | return DI; |
| 2069 | |
| 2070 | TypeLocBuilder TLB; |
| 2071 | |
| 2072 | TypeLoc TL = DI->getTypeLoc(); |
| 2073 | TLB.reserve(TL.getFullDataSize()); |
| 2074 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2075 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2076 | if (Result.isNull()) |
| 2077 | return 0; |
| 2078 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2079 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | template<typename Derived> |
| 2083 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2084 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2085 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2086 | switch (T.getTypeLocClass()) { |
| 2087 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2088 | #define TYPELOC(CLASS, PARENT) \ |
| 2089 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2090 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2091 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2092 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2095 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2096 | return QualType(); |
| 2097 | } |
| 2098 | |
| 2099 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2100 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2101 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2102 | /// types). This is the right thing for template instantiation, but |
| 2103 | /// probably not for other clients. |
| 2104 | template<typename Derived> |
| 2105 | QualType |
| 2106 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2107 | QualifiedTypeLoc T, |
| 2108 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2109 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2110 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2111 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2112 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2113 | if (Result.isNull()) |
| 2114 | return QualType(); |
| 2115 | |
| 2116 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2117 | // FIXME: this is the right thing for template instantiation, but |
| 2118 | // probably not for other clients. |
| 2119 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2120 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2121 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2122 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2123 | |
| 2124 | TLB.push<QualifiedTypeLoc>(Result); |
| 2125 | |
| 2126 | // No location information to preserve. |
| 2127 | |
| 2128 | return Result; |
| 2129 | } |
| 2130 | |
| 2131 | template <class TyLoc> static inline |
| 2132 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2133 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2134 | NewT.setNameLoc(T.getNameLoc()); |
| 2135 | return T.getType(); |
| 2136 | } |
| 2137 | |
| 2138 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2139 | // the equivalent template version work. |
| 2140 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2141 | QualType PointeeType \ |
| 2142 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2143 | if (PointeeType.isNull()) \ |
| 2144 | return QualType(); \ |
| 2145 | \ |
| 2146 | QualType Result = TL.getType(); \ |
| 2147 | if (getDerived().AlwaysRebuild() || \ |
| 2148 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2149 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2150 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2151 | if (Result.isNull()) \ |
| 2152 | return QualType(); \ |
| 2153 | } \ |
| 2154 | \ |
| 2155 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2156 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2157 | \ |
| 2158 | return Result; \ |
| 2159 | } while(0) |
| 2160 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2161 | template<typename Derived> |
| 2162 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2163 | BuiltinTypeLoc T, |
| 2164 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2165 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2166 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2167 | if (T.needsExtraLocalData()) |
| 2168 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2169 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2170 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2172 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2173 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2174 | ComplexTypeLoc T, |
| 2175 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2176 | // FIXME: recurse? |
| 2177 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2179 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2180 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2181 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2182 | PointerTypeLoc TL, |
| 2183 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2184 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2185 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2186 | |
| 2187 | template<typename Derived> |
| 2188 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2189 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2190 | BlockPointerTypeLoc TL, |
| 2191 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2192 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2195 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2196 | /// don't care whether the type itself is an l-value type or an r-value |
| 2197 | /// type; we only care if the type was *written* as an l-value type |
| 2198 | /// or an r-value type. |
| 2199 | template<typename Derived> |
| 2200 | QualType |
| 2201 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2202 | ReferenceTypeLoc TL, |
| 2203 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2204 | const ReferenceType *T = TL.getTypePtr(); |
| 2205 | |
| 2206 | // Note that this works with the pointee-as-written. |
| 2207 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2208 | if (PointeeType.isNull()) |
| 2209 | return QualType(); |
| 2210 | |
| 2211 | QualType Result = TL.getType(); |
| 2212 | if (getDerived().AlwaysRebuild() || |
| 2213 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2214 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2215 | T->isSpelledAsLValue(), |
| 2216 | TL.getSigilLoc()); |
| 2217 | if (Result.isNull()) |
| 2218 | return QualType(); |
| 2219 | } |
| 2220 | |
| 2221 | // r-value references can be rebuilt as l-value references. |
| 2222 | ReferenceTypeLoc NewTL; |
| 2223 | if (isa<LValueReferenceType>(Result)) |
| 2224 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2225 | else |
| 2226 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2227 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2228 | |
| 2229 | return Result; |
| 2230 | } |
| 2231 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2232 | template<typename Derived> |
| 2233 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2234 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2235 | LValueReferenceTypeLoc TL, |
| 2236 | QualType ObjectType) { |
| 2237 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2240 | template<typename Derived> |
| 2241 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2242 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2243 | RValueReferenceTypeLoc TL, |
| 2244 | QualType ObjectType) { |
| 2245 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2246 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2247 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2248 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2249 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2250 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2251 | MemberPointerTypeLoc TL, |
| 2252 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2253 | MemberPointerType *T = TL.getTypePtr(); |
| 2254 | |
| 2255 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2256 | if (PointeeType.isNull()) |
| 2257 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2258 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2259 | // TODO: preserve source information for this. |
| 2260 | QualType ClassType |
| 2261 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2262 | if (ClassType.isNull()) |
| 2263 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2264 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2265 | QualType Result = TL.getType(); |
| 2266 | if (getDerived().AlwaysRebuild() || |
| 2267 | PointeeType != T->getPointeeType() || |
| 2268 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2269 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2270 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2271 | if (Result.isNull()) |
| 2272 | return QualType(); |
| 2273 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2274 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2275 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2276 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2277 | |
| 2278 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2281 | template<typename Derived> |
| 2282 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2283 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2284 | ConstantArrayTypeLoc TL, |
| 2285 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2286 | ConstantArrayType *T = TL.getTypePtr(); |
| 2287 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2288 | if (ElementType.isNull()) |
| 2289 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2291 | QualType Result = TL.getType(); |
| 2292 | if (getDerived().AlwaysRebuild() || |
| 2293 | ElementType != T->getElementType()) { |
| 2294 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2295 | T->getSizeModifier(), |
| 2296 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2297 | T->getIndexTypeCVRQualifiers(), |
| 2298 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2299 | if (Result.isNull()) |
| 2300 | return QualType(); |
| 2301 | } |
| 2302 | |
| 2303 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2304 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2305 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2306 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2307 | Expr *Size = TL.getSizeExpr(); |
| 2308 | if (Size) { |
| 2309 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2310 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2311 | } |
| 2312 | NewTL.setSizeExpr(Size); |
| 2313 | |
| 2314 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2315 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2317 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2318 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2319 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2320 | IncompleteArrayTypeLoc TL, |
| 2321 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2322 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2323 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2324 | if (ElementType.isNull()) |
| 2325 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2326 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2327 | QualType Result = TL.getType(); |
| 2328 | if (getDerived().AlwaysRebuild() || |
| 2329 | ElementType != T->getElementType()) { |
| 2330 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2331 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2332 | T->getIndexTypeCVRQualifiers(), |
| 2333 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2334 | if (Result.isNull()) |
| 2335 | return QualType(); |
| 2336 | } |
| 2337 | |
| 2338 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2339 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2340 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2341 | NewTL.setSizeExpr(0); |
| 2342 | |
| 2343 | return Result; |
| 2344 | } |
| 2345 | |
| 2346 | template<typename Derived> |
| 2347 | QualType |
| 2348 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2349 | VariableArrayTypeLoc TL, |
| 2350 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2351 | VariableArrayType *T = TL.getTypePtr(); |
| 2352 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2353 | if (ElementType.isNull()) |
| 2354 | return QualType(); |
| 2355 | |
| 2356 | // Array bounds are not potentially evaluated contexts |
| 2357 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2358 | |
| 2359 | Sema::OwningExprResult SizeResult |
| 2360 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2361 | if (SizeResult.isInvalid()) |
| 2362 | return QualType(); |
| 2363 | |
| 2364 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2365 | |
| 2366 | QualType Result = TL.getType(); |
| 2367 | if (getDerived().AlwaysRebuild() || |
| 2368 | ElementType != T->getElementType() || |
| 2369 | Size != T->getSizeExpr()) { |
| 2370 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2371 | T->getSizeModifier(), |
| 2372 | move(SizeResult), |
| 2373 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2374 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2375 | if (Result.isNull()) |
| 2376 | return QualType(); |
| 2377 | } |
| 2378 | else SizeResult.take(); |
| 2379 | |
| 2380 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2381 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2382 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2383 | NewTL.setSizeExpr(Size); |
| 2384 | |
| 2385 | return Result; |
| 2386 | } |
| 2387 | |
| 2388 | template<typename Derived> |
| 2389 | QualType |
| 2390 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2391 | DependentSizedArrayTypeLoc TL, |
| 2392 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2393 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2394 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2395 | if (ElementType.isNull()) |
| 2396 | return QualType(); |
| 2397 | |
| 2398 | // Array bounds are not potentially evaluated contexts |
| 2399 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2400 | |
| 2401 | Sema::OwningExprResult SizeResult |
| 2402 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2403 | if (SizeResult.isInvalid()) |
| 2404 | return QualType(); |
| 2405 | |
| 2406 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2407 | |
| 2408 | QualType Result = TL.getType(); |
| 2409 | if (getDerived().AlwaysRebuild() || |
| 2410 | ElementType != T->getElementType() || |
| 2411 | Size != T->getSizeExpr()) { |
| 2412 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2413 | T->getSizeModifier(), |
| 2414 | move(SizeResult), |
| 2415 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2416 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2417 | if (Result.isNull()) |
| 2418 | return QualType(); |
| 2419 | } |
| 2420 | else SizeResult.take(); |
| 2421 | |
| 2422 | // We might have any sort of array type now, but fortunately they |
| 2423 | // all have the same location layout. |
| 2424 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2425 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2426 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2427 | NewTL.setSizeExpr(Size); |
| 2428 | |
| 2429 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2430 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2431 | |
| 2432 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2433 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2434 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2435 | DependentSizedExtVectorTypeLoc TL, |
| 2436 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2437 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2438 | |
| 2439 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2440 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2441 | if (ElementType.isNull()) |
| 2442 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2444 | // Vector sizes are not potentially evaluated contexts |
| 2445 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2446 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2447 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2448 | if (Size.isInvalid()) |
| 2449 | return QualType(); |
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 | QualType Result = TL.getType(); |
| 2452 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2453 | ElementType != T->getElementType() || |
| 2454 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2455 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2456 | move(Size), |
| 2457 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2458 | if (Result.isNull()) |
| 2459 | return QualType(); |
| 2460 | } |
| 2461 | else Size.take(); |
| 2462 | |
| 2463 | // Result might be dependent or not. |
| 2464 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2465 | DependentSizedExtVectorTypeLoc NewTL |
| 2466 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2467 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2468 | } else { |
| 2469 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2470 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2471 | } |
| 2472 | |
| 2473 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2475 | |
| 2476 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2477 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2478 | VectorTypeLoc TL, |
| 2479 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2480 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2481 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2482 | if (ElementType.isNull()) |
| 2483 | return QualType(); |
| 2484 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2485 | QualType Result = TL.getType(); |
| 2486 | if (getDerived().AlwaysRebuild() || |
| 2487 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2488 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2489 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2490 | if (Result.isNull()) |
| 2491 | return QualType(); |
| 2492 | } |
| 2493 | |
| 2494 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2495 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2496 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | return Result; |
| 2498 | } |
| 2499 | |
| 2500 | template<typename Derived> |
| 2501 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2502 | ExtVectorTypeLoc TL, |
| 2503 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2504 | VectorType *T = TL.getTypePtr(); |
| 2505 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2506 | if (ElementType.isNull()) |
| 2507 | return QualType(); |
| 2508 | |
| 2509 | QualType Result = TL.getType(); |
| 2510 | if (getDerived().AlwaysRebuild() || |
| 2511 | ElementType != T->getElementType()) { |
| 2512 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2513 | T->getNumElements(), |
| 2514 | /*FIXME*/ SourceLocation()); |
| 2515 | if (Result.isNull()) |
| 2516 | return QualType(); |
| 2517 | } |
| 2518 | |
| 2519 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2520 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2521 | |
| 2522 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2524 | |
| 2525 | template<typename Derived> |
| 2526 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2527 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2528 | FunctionProtoTypeLoc TL, |
| 2529 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2530 | FunctionProtoType *T = TL.getTypePtr(); |
| 2531 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2532 | if (ResultType.isNull()) |
| 2533 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2534 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2535 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2536 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2537 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2538 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2539 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2540 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2541 | QualType NewType; |
| 2542 | ParmVarDecl *NewParm; |
| 2543 | |
| 2544 | if (OldParm) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2545 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2546 | assert(OldDI->getType() == T->getArgType(i)); |
| 2547 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2548 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2549 | if (!NewDI) |
| 2550 | return QualType(); |
| 2551 | |
| 2552 | if (NewDI == OldDI) |
| 2553 | NewParm = OldParm; |
| 2554 | else |
| 2555 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2556 | OldParm->getDeclContext(), |
| 2557 | OldParm->getLocation(), |
| 2558 | OldParm->getIdentifier(), |
| 2559 | NewDI->getType(), |
| 2560 | NewDI, |
| 2561 | OldParm->getStorageClass(), |
| 2562 | /* DefArg */ NULL); |
| 2563 | NewType = NewParm->getType(); |
| 2564 | |
| 2565 | // Deal with the possibility that we don't have a parameter |
| 2566 | // declaration for this parameter. |
| 2567 | } else { |
| 2568 | NewParm = 0; |
| 2569 | |
| 2570 | QualType OldType = T->getArgType(i); |
| 2571 | NewType = getDerived().TransformType(OldType); |
| 2572 | if (NewType.isNull()) |
| 2573 | return QualType(); |
| 2574 | } |
| 2575 | |
| 2576 | ParamTypes.push_back(NewType); |
| 2577 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2578 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2579 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2580 | QualType Result = TL.getType(); |
| 2581 | if (getDerived().AlwaysRebuild() || |
| 2582 | ResultType != T->getResultType() || |
| 2583 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2584 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2585 | ParamTypes.data(), |
| 2586 | ParamTypes.size(), |
| 2587 | T->isVariadic(), |
| 2588 | T->getTypeQuals()); |
| 2589 | if (Result.isNull()) |
| 2590 | return QualType(); |
| 2591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2592 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2593 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2594 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2595 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2596 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2597 | NewTL.setArg(i, ParamDecls[i]); |
| 2598 | |
| 2599 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2601 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2602 | template<typename Derived> |
| 2603 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2604 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2605 | FunctionNoProtoTypeLoc TL, |
| 2606 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2607 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2608 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2609 | if (ResultType.isNull()) |
| 2610 | return QualType(); |
| 2611 | |
| 2612 | QualType Result = TL.getType(); |
| 2613 | if (getDerived().AlwaysRebuild() || |
| 2614 | ResultType != T->getResultType()) |
| 2615 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2616 | |
| 2617 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2618 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2619 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2620 | |
| 2621 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2624 | template<typename Derived> QualType |
| 2625 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2626 | UnresolvedUsingTypeLoc TL, |
| 2627 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2628 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2629 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2630 | if (!D) |
| 2631 | return QualType(); |
| 2632 | |
| 2633 | QualType Result = TL.getType(); |
| 2634 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2635 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2636 | if (Result.isNull()) |
| 2637 | return QualType(); |
| 2638 | } |
| 2639 | |
| 2640 | // We might get an arbitrary type spec type back. We should at |
| 2641 | // least always get a type spec type, though. |
| 2642 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2643 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2644 | |
| 2645 | return Result; |
| 2646 | } |
| 2647 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2648 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2650 | TypedefTypeLoc TL, |
| 2651 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2652 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2653 | TypedefDecl *Typedef |
| 2654 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2655 | if (!Typedef) |
| 2656 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2657 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2658 | QualType Result = TL.getType(); |
| 2659 | if (getDerived().AlwaysRebuild() || |
| 2660 | Typedef != T->getDecl()) { |
| 2661 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2662 | if (Result.isNull()) |
| 2663 | return QualType(); |
| 2664 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2665 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2666 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2667 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2668 | |
| 2669 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2670 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2671 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2672 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2673 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2674 | TypeOfExprTypeLoc TL, |
| 2675 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2676 | // typeof expressions are not potentially evaluated contexts |
| 2677 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2678 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2679 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2680 | if (E.isInvalid()) |
| 2681 | return QualType(); |
| 2682 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | QualType Result = TL.getType(); |
| 2684 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2685 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2686 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2687 | if (Result.isNull()) |
| 2688 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2689 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2692 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2693 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2694 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2695 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2696 | |
| 2697 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2698 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2699 | |
| 2700 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2701 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2702 | TypeOfTypeLoc TL, |
| 2703 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2704 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2705 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2706 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2707 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2708 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2709 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2710 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2711 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2712 | if (Result.isNull()) |
| 2713 | return QualType(); |
| 2714 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2715 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2717 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2718 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2719 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2720 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2721 | |
| 2722 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2723 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2724 | |
| 2725 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2727 | DecltypeTypeLoc TL, |
| 2728 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2729 | DecltypeType *T = TL.getTypePtr(); |
| 2730 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2731 | // decltype expressions are not potentially evaluated contexts |
| 2732 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2733 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2734 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2735 | if (E.isInvalid()) |
| 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 | QualType Result = TL.getType(); |
| 2739 | if (getDerived().AlwaysRebuild() || |
| 2740 | E.get() != T->getUnderlyingExpr()) { |
| 2741 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2742 | if (Result.isNull()) |
| 2743 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2744 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2745 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2746 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2747 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2748 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2749 | |
| 2750 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2755 | RecordTypeLoc TL, |
| 2756 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2757 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2758 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2759 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2760 | if (!Record) |
| 2761 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2762 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2763 | QualType Result = TL.getType(); |
| 2764 | if (getDerived().AlwaysRebuild() || |
| 2765 | Record != T->getDecl()) { |
| 2766 | Result = getDerived().RebuildRecordType(Record); |
| 2767 | if (Result.isNull()) |
| 2768 | return QualType(); |
| 2769 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2772 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2773 | |
| 2774 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2775 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | |
| 2777 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2778 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2779 | EnumTypeLoc TL, |
| 2780 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2781 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2782 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2784 | if (!Enum) |
| 2785 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2786 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2787 | QualType Result = TL.getType(); |
| 2788 | if (getDerived().AlwaysRebuild() || |
| 2789 | Enum != T->getDecl()) { |
| 2790 | Result = getDerived().RebuildEnumType(Enum); |
| 2791 | if (Result.isNull()) |
| 2792 | return QualType(); |
| 2793 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2796 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2797 | |
| 2798 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2799 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2800 | |
| 2801 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2803 | ElaboratedTypeLoc TL, |
| 2804 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2805 | ElaboratedType *T = TL.getTypePtr(); |
| 2806 | |
| 2807 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2808 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2809 | if (Underlying.isNull()) |
| 2810 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2811 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2812 | QualType Result = TL.getType(); |
| 2813 | if (getDerived().AlwaysRebuild() || |
| 2814 | Underlying != T->getUnderlyingType()) { |
| 2815 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2816 | if (Result.isNull()) |
| 2817 | return QualType(); |
| 2818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2819 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2820 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2821 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2822 | |
| 2823 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2824 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2825 | |
| 2826 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2827 | template<typename Derived> |
| 2828 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2830 | TemplateTypeParmTypeLoc TL, |
| 2831 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2832 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2836 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2838 | SubstTemplateTypeParmTypeLoc TL, |
| 2839 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2840 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2844 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2845 | const TemplateSpecializationType *TST, |
| 2846 | QualType ObjectType) { |
| 2847 | // FIXME: this entire method is a temporary workaround; callers |
| 2848 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2849 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2850 | // Fake up a TemplateSpecializationTypeLoc. |
| 2851 | TypeLocBuilder TLB; |
| 2852 | TemplateSpecializationTypeLoc TL |
| 2853 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2854 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2855 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2856 | |
| 2857 | TL.setTemplateNameLoc(BaseLoc); |
| 2858 | TL.setLAngleLoc(BaseLoc); |
| 2859 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2860 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2861 | const TemplateArgument &TA = TST->getArg(i); |
| 2862 | TemplateArgumentLoc TAL; |
| 2863 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2864 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2865 | } |
| 2866 | |
| 2867 | TypeLocBuilder IgnoredTLB; |
| 2868 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2872 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2873 | TypeLocBuilder &TLB, |
| 2874 | TemplateSpecializationTypeLoc TL, |
| 2875 | QualType ObjectType) { |
| 2876 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2877 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2878 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2879 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2880 | if (Template.isNull()) |
| 2881 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2882 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2883 | TemplateArgumentListInfo NewTemplateArgs; |
| 2884 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2885 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2886 | |
| 2887 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2888 | TemplateArgumentLoc Loc; |
| 2889 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2890 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2891 | NewTemplateArgs.addArgument(Loc); |
| 2892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2894 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2895 | |
| 2896 | QualType Result = |
| 2897 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2898 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2899 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2900 | |
| 2901 | if (!Result.isNull()) { |
| 2902 | TemplateSpecializationTypeLoc NewTL |
| 2903 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2904 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2905 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2906 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2907 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2908 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2911 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2912 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2913 | |
| 2914 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2915 | QualType |
| 2916 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2917 | QualifiedNameTypeLoc TL, |
| 2918 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2919 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2920 | NestedNameSpecifier *NNS |
| 2921 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2922 | SourceRange(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 2923 | false, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2924 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2925 | if (!NNS) |
| 2926 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2927 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2928 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2929 | if (Named.isNull()) |
| 2930 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | QualType Result = TL.getType(); |
| 2933 | if (getDerived().AlwaysRebuild() || |
| 2934 | NNS != T->getQualifier() || |
| 2935 | Named != T->getNamedType()) { |
| 2936 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2937 | if (Result.isNull()) |
| 2938 | return QualType(); |
| 2939 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2940 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2941 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2942 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2943 | |
| 2944 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2945 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2946 | |
| 2947 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2948 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2949 | TypenameTypeLoc TL, |
| 2950 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2951 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2952 | |
| 2953 | /* FIXME: preserve source information better than this */ |
| 2954 | SourceRange SR(TL.getNameLoc()); |
| 2955 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2956 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2957 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 2958 | false, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2959 | if (!NNS) |
| 2960 | return QualType(); |
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 | QualType Result; |
| 2963 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2964 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2965 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2966 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2967 | if (NewTemplateId.isNull()) |
| 2968 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2970 | if (!getDerived().AlwaysRebuild() && |
| 2971 | NNS == T->getQualifier() && |
| 2972 | NewTemplateId == QualType(TemplateId, 0)) |
| 2973 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2975 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2976 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2977 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2978 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2979 | if (Result.isNull()) |
| 2980 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2981 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2982 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2983 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2984 | |
| 2985 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2987 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2988 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2989 | QualType |
| 2990 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2991 | ObjCInterfaceTypeLoc TL, |
| 2992 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2993 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2994 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2996 | |
| 2997 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2998 | QualType |
| 2999 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3000 | ObjCObjectPointerTypeLoc TL, |
| 3001 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3002 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3003 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3006 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3007 | // Statement transformation |
| 3008 | //===----------------------------------------------------------------------===// |
| 3009 | template<typename Derived> |
| 3010 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3012 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | template<typename Derived> |
| 3016 | Sema::OwningStmtResult |
| 3017 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3018 | return getDerived().TransformCompoundStmt(S, false); |
| 3019 | } |
| 3020 | |
| 3021 | template<typename Derived> |
| 3022 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3023 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3024 | bool IsStmtExpr) { |
| 3025 | bool SubStmtChanged = false; |
| 3026 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3027 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3028 | B != BEnd; ++B) { |
| 3029 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3030 | if (Result.isInvalid()) |
| 3031 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3032 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3033 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3034 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3037 | if (!getDerived().AlwaysRebuild() && |
| 3038 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3040 | |
| 3041 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3042 | move_arg(Statements), |
| 3043 | S->getRBracLoc(), |
| 3044 | IsStmtExpr); |
| 3045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3047 | template<typename Derived> |
| 3048 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3049 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3050 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3051 | { |
| 3052 | // The case value expressions are not potentially evaluated. |
| 3053 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3054 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3055 | // Transform the left-hand case value. |
| 3056 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3057 | if (LHS.isInvalid()) |
| 3058 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3059 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3060 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3061 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3062 | if (RHS.isInvalid()) |
| 3063 | return SemaRef.StmtError(); |
| 3064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3065 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3066 | // Build the case statement. |
| 3067 | // Case statements are always rebuilt so that they will attached to their |
| 3068 | // transformed switch statement. |
| 3069 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3070 | move(LHS), |
| 3071 | S->getEllipsisLoc(), |
| 3072 | move(RHS), |
| 3073 | S->getColonLoc()); |
| 3074 | if (Case.isInvalid()) |
| 3075 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3076 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3077 | // Transform the statement following the case |
| 3078 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3079 | if (SubStmt.isInvalid()) |
| 3080 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3082 | // Attach the body to the case statement |
| 3083 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3084 | } |
| 3085 | |
| 3086 | template<typename Derived> |
| 3087 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3089 | // Transform the statement following the default case |
| 3090 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3091 | if (SubStmt.isInvalid()) |
| 3092 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3094 | // Default statements are always rebuilt |
| 3095 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3096 | move(SubStmt)); |
| 3097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | template<typename Derived> |
| 3100 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3101 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3102 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3103 | if (SubStmt.isInvalid()) |
| 3104 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3105 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3106 | // FIXME: Pass the real colon location in. |
| 3107 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3108 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3109 | move(SubStmt)); |
| 3110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3112 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3113 | Sema::OwningStmtResult |
| 3114 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3115 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3116 | OwningExprResult Cond(SemaRef); |
| 3117 | VarDecl *ConditionVar = 0; |
| 3118 | if (S->getConditionVariable()) { |
| 3119 | ConditionVar |
| 3120 | = cast_or_null<VarDecl>( |
| 3121 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3122 | if (!ConditionVar) |
| 3123 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3124 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3125 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3126 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3127 | if (Cond.isInvalid()) |
| 3128 | return SemaRef.StmtError(); |
| 3129 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3130 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3131 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3133 | // Transform the "then" branch. |
| 3134 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3135 | if (Then.isInvalid()) |
| 3136 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3138 | // Transform the "else" branch. |
| 3139 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3140 | if (Else.isInvalid()) |
| 3141 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3142 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3143 | if (!getDerived().AlwaysRebuild() && |
| 3144 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3145 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3146 | Then.get() == S->getThen() && |
| 3147 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3148 | return SemaRef.Owned(S->Retain()); |
| 3149 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3150 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3151 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3152 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | template<typename Derived> |
| 3156 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3157 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3158 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3159 | OwningExprResult Cond(SemaRef); |
| 3160 | VarDecl *ConditionVar = 0; |
| 3161 | if (S->getConditionVariable()) { |
| 3162 | ConditionVar |
| 3163 | = cast_or_null<VarDecl>( |
| 3164 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3165 | if (!ConditionVar) |
| 3166 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3167 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3168 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3169 | |
| 3170 | if (Cond.isInvalid()) |
| 3171 | return SemaRef.StmtError(); |
| 3172 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3174 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3175 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3176 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3177 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3178 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3179 | if (Switch.isInvalid()) |
| 3180 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | // Transform the body of the switch statement. |
| 3183 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3184 | if (Body.isInvalid()) |
| 3185 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3187 | // Complete the switch statement. |
| 3188 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3189 | move(Body)); |
| 3190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3192 | template<typename Derived> |
| 3193 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3195 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3196 | OwningExprResult Cond(SemaRef); |
| 3197 | VarDecl *ConditionVar = 0; |
| 3198 | if (S->getConditionVariable()) { |
| 3199 | ConditionVar |
| 3200 | = cast_or_null<VarDecl>( |
| 3201 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3202 | if (!ConditionVar) |
| 3203 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3204 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3205 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3206 | |
| 3207 | if (Cond.isInvalid()) |
| 3208 | return SemaRef.StmtError(); |
| 3209 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3210 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3211 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3212 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3213 | // Transform the body |
| 3214 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3215 | if (Body.isInvalid()) |
| 3216 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3218 | if (!getDerived().AlwaysRebuild() && |
| 3219 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3220 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3222 | return SemaRef.Owned(S->Retain()); |
| 3223 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3224 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3225 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3227 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3228 | template<typename Derived> |
| 3229 | Sema::OwningStmtResult |
| 3230 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3231 | // Transform the condition |
| 3232 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3233 | if (Cond.isInvalid()) |
| 3234 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3235 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3236 | // Transform the body |
| 3237 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3238 | if (Body.isInvalid()) |
| 3239 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3241 | if (!getDerived().AlwaysRebuild() && |
| 3242 | Cond.get() == S->getCond() && |
| 3243 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | return SemaRef.Owned(S->Retain()); |
| 3245 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3246 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3247 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3248 | S->getRParenLoc()); |
| 3249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3251 | template<typename Derived> |
| 3252 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3253 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3254 | // Transform the initialization statement |
| 3255 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3256 | if (Init.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 condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3260 | OwningExprResult Cond(SemaRef); |
| 3261 | VarDecl *ConditionVar = 0; |
| 3262 | if (S->getConditionVariable()) { |
| 3263 | ConditionVar |
| 3264 | = cast_or_null<VarDecl>( |
| 3265 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3266 | if (!ConditionVar) |
| 3267 | return SemaRef.StmtError(); |
| 3268 | } else { |
| 3269 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3270 | |
| 3271 | if (Cond.isInvalid()) |
| 3272 | return SemaRef.StmtError(); |
| 3273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3274 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3275 | // Transform the increment |
| 3276 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3277 | if (Inc.isInvalid()) |
| 3278 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3280 | // Transform the body |
| 3281 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3282 | if (Body.isInvalid()) |
| 3283 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3284 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3285 | if (!getDerived().AlwaysRebuild() && |
| 3286 | Init.get() == S->getInit() && |
| 3287 | Cond.get() == S->getCond() && |
| 3288 | Inc.get() == S->getInc() && |
| 3289 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | return SemaRef.Owned(S->Retain()); |
| 3291 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3293 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3294 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3295 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3296 | S->getRParenLoc(), move(Body)); |
| 3297 | } |
| 3298 | |
| 3299 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | Sema::OwningStmtResult |
| 3301 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3302 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | S->getLabel()); |
| 3305 | } |
| 3306 | |
| 3307 | template<typename Derived> |
| 3308 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3311 | if (Target.isInvalid()) |
| 3312 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | if (!getDerived().AlwaysRebuild() && |
| 3315 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | |
| 3318 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3319 | move(Target)); |
| 3320 | } |
| 3321 | |
| 3322 | template<typename Derived> |
| 3323 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3325 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3327 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3328 | template<typename Derived> |
| 3329 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3330 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3331 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3334 | template<typename Derived> |
| 3335 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3338 | if (Result.isInvalid()) |
| 3339 | return SemaRef.StmtError(); |
| 3340 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | // to tell whether the return type of the function has changed. |
| 3343 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3344 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | template<typename Derived> |
| 3347 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | bool DeclChanged = false; |
| 3350 | llvm::SmallVector<Decl *, 4> Decls; |
| 3351 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3352 | D != DEnd; ++D) { |
| 3353 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3354 | if (!Transformed) |
| 3355 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | if (Transformed != *D) |
| 3358 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3360 | Decls.push_back(Transformed); |
| 3361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3364 | return SemaRef.Owned(S->Retain()); |
| 3365 | |
| 3366 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3367 | S->getStartLoc(), S->getEndLoc()); |
| 3368 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3369 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3370 | template<typename Derived> |
| 3371 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3372 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3373 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | template<typename Derived> |
| 3378 | Sema::OwningStmtResult |
| 3379 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3380 | |
| 3381 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3382 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3383 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3384 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3385 | OwningExprResult AsmString(SemaRef); |
| 3386 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3387 | |
| 3388 | bool ExprsChanged = false; |
| 3389 | |
| 3390 | // Go through the outputs. |
| 3391 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3392 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3393 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3394 | // No need to transform the constraint literal. |
| 3395 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3396 | |
| 3397 | // Transform the output expr. |
| 3398 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3399 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3400 | if (Result.isInvalid()) |
| 3401 | return SemaRef.StmtError(); |
| 3402 | |
| 3403 | ExprsChanged |= Result.get() != OutputExpr; |
| 3404 | |
| 3405 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3406 | } |
| 3407 | |
| 3408 | // Go through the inputs. |
| 3409 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3410 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3411 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3412 | // No need to transform the constraint literal. |
| 3413 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3414 | |
| 3415 | // Transform the input expr. |
| 3416 | Expr *InputExpr = S->getInputExpr(I); |
| 3417 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3418 | if (Result.isInvalid()) |
| 3419 | return SemaRef.StmtError(); |
| 3420 | |
| 3421 | ExprsChanged |= Result.get() != InputExpr; |
| 3422 | |
| 3423 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3424 | } |
| 3425 | |
| 3426 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3427 | return SemaRef.Owned(S->Retain()); |
| 3428 | |
| 3429 | // Go through the clobbers. |
| 3430 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3431 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3432 | |
| 3433 | // No need to transform the asm string literal. |
| 3434 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3435 | |
| 3436 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3437 | S->isSimple(), |
| 3438 | S->isVolatile(), |
| 3439 | S->getNumOutputs(), |
| 3440 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3441 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3442 | move_arg(Constraints), |
| 3443 | move_arg(Exprs), |
| 3444 | move(AsmString), |
| 3445 | move_arg(Clobbers), |
| 3446 | S->getRParenLoc(), |
| 3447 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | |
| 3451 | template<typename Derived> |
| 3452 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3453 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3454 | // FIXME: Implement this |
| 3455 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3457 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3459 | template<typename Derived> |
| 3460 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | // FIXME: Implement this |
| 3463 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3464 | return SemaRef.Owned(S->Retain()); |
| 3465 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3466 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3467 | template<typename Derived> |
| 3468 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3470 | // FIXME: Implement this |
| 3471 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3472 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3473 | } |
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 | template<typename Derived> |
| 3476 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3477 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3478 | // FIXME: Implement this |
| 3479 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3481 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3483 | template<typename Derived> |
| 3484 | Sema::OwningStmtResult |
| 3485 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3487 | // FIXME: Implement this |
| 3488 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | template<typename Derived> |
| 3493 | Sema::OwningStmtResult |
| 3494 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3495 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3496 | // FIXME: Implement this |
| 3497 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | |
| 3502 | template<typename Derived> |
| 3503 | Sema::OwningStmtResult |
| 3504 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3505 | // Transform the exception declaration, if any. |
| 3506 | VarDecl *Var = 0; |
| 3507 | if (S->getExceptionDecl()) { |
| 3508 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3509 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3510 | ExceptionDecl->getDeclName()); |
| 3511 | |
| 3512 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3513 | if (T.isNull()) |
| 3514 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3515 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3516 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3517 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3518 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3519 | ExceptionDecl->getIdentifier(), |
| 3520 | ExceptionDecl->getLocation(), |
| 3521 | /*FIXME: Inaccurate*/ |
| 3522 | SourceRange(ExceptionDecl->getLocation())); |
| 3523 | if (!Var || Var->isInvalidDecl()) { |
| 3524 | if (Var) |
| 3525 | Var->Destroy(SemaRef.Context); |
| 3526 | return SemaRef.StmtError(); |
| 3527 | } |
| 3528 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3529 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3530 | // Transform the actual exception handler. |
| 3531 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3532 | if (Handler.isInvalid()) { |
| 3533 | if (Var) |
| 3534 | Var->Destroy(SemaRef.Context); |
| 3535 | return SemaRef.StmtError(); |
| 3536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3538 | if (!getDerived().AlwaysRebuild() && |
| 3539 | !Var && |
| 3540 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | |
| 3543 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3544 | Var, |
| 3545 | move(Handler)); |
| 3546 | } |
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 | template<typename Derived> |
| 3549 | Sema::OwningStmtResult |
| 3550 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3551 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3553 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3554 | if (TryBlock.isInvalid()) |
| 3555 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3556 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3557 | // Transform the handlers. |
| 3558 | bool HandlerChanged = false; |
| 3559 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3560 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3562 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3563 | if (Handler.isInvalid()) |
| 3564 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3566 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3567 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3568 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3570 | if (!getDerived().AlwaysRebuild() && |
| 3571 | TryBlock.get() == S->getTryBlock() && |
| 3572 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3573 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3574 | |
| 3575 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3576 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3577 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3578 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3579 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3580 | // Expression transformation |
| 3581 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | template<typename Derived> |
| 3583 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3584 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3586 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3587 | |
| 3588 | template<typename Derived> |
| 3589 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3590 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3591 | NestedNameSpecifier *Qualifier = 0; |
| 3592 | if (E->getQualifier()) { |
| 3593 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 3594 | E->getQualifierRange(), |
| 3595 | false); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3596 | if (!Qualifier) |
| 3597 | return SemaRef.ExprError(); |
| 3598 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3599 | |
| 3600 | ValueDecl *ND |
| 3601 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3602 | if (!ND) |
| 3603 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3605 | if (!getDerived().AlwaysRebuild() && |
| 3606 | Qualifier == E->getQualifier() && |
| 3607 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3608 | !E->hasExplicitTemplateArgumentList()) { |
| 3609 | |
| 3610 | // Mark it referenced in the new context regardless. |
| 3611 | // FIXME: this is a bit instantiation-specific. |
| 3612 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3613 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3615 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3616 | |
| 3617 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3618 | if (E->hasExplicitTemplateArgumentList()) { |
| 3619 | TemplateArgs = &TransArgs; |
| 3620 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3621 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3622 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3623 | TemplateArgumentLoc Loc; |
| 3624 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3625 | return SemaRef.ExprError(); |
| 3626 | TransArgs.addArgument(Loc); |
| 3627 | } |
| 3628 | } |
| 3629 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3630 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3631 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3633 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3634 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3636 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3638 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3640 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3641 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3642 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3648 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3652 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3654 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3658 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3660 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | return SemaRef.Owned(E->Retain()); |
| 3662 | } |
| 3663 | |
| 3664 | template<typename Derived> |
| 3665 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3666 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3667 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3668 | if (SubExpr.isInvalid()) |
| 3669 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3671 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | return SemaRef.Owned(E->Retain()); |
| 3673 | |
| 3674 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | E->getRParen()); |
| 3676 | } |
| 3677 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | template<typename Derived> |
| 3679 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3680 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3681 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3682 | if (SubExpr.isInvalid()) |
| 3683 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3685 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | return SemaRef.Owned(E->Retain()); |
| 3687 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3688 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3689 | E->getOpcode(), |
| 3690 | move(SubExpr)); |
| 3691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3693 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3695 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3696 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3697 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3698 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3699 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3700 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3701 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3703 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3704 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3706 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3707 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3708 | E->getSourceRange()); |
| 3709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3710 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3711 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3713 | // C++0x [expr.sizeof]p1: |
| 3714 | // The operand is either an expression, which is an unevaluated operand |
| 3715 | // [...] |
| 3716 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3718 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3719 | if (SubExpr.isInvalid()) |
| 3720 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3723 | return SemaRef.Owned(E->Retain()); |
| 3724 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3726 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3727 | E->isSizeOf(), |
| 3728 | E->getSourceRange()); |
| 3729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3731 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3732 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3733 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3734 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3735 | if (LHS.isInvalid()) |
| 3736 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3737 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3738 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3739 | if (RHS.isInvalid()) |
| 3740 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3741 | |
| 3742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3743 | if (!getDerived().AlwaysRebuild() && |
| 3744 | LHS.get() == E->getLHS() && |
| 3745 | RHS.get() == E->getRHS()) |
| 3746 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3749 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3750 | move(RHS), |
| 3751 | E->getRBracketLoc()); |
| 3752 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
| 3754 | template<typename Derived> |
| 3755 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3756 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3757 | // Transform the callee. |
| 3758 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3759 | if (Callee.isInvalid()) |
| 3760 | return SemaRef.ExprError(); |
| 3761 | |
| 3762 | // Transform arguments. |
| 3763 | bool ArgChanged = false; |
| 3764 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3765 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3766 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3767 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3768 | if (Arg.isInvalid()) |
| 3769 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3770 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | // FIXME: Wrong source location information for the ','. |
| 3772 | FakeCommaLocs.push_back( |
| 3773 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3774 | |
| 3775 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | Args.push_back(Arg.takeAs<Expr>()); |
| 3777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3779 | if (!getDerived().AlwaysRebuild() && |
| 3780 | Callee.get() == E->getCallee() && |
| 3781 | !ArgChanged) |
| 3782 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3784 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3785 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3786 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3787 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3788 | move_arg(Args), |
| 3789 | FakeCommaLocs.data(), |
| 3790 | E->getRParenLoc()); |
| 3791 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
| 3793 | template<typename Derived> |
| 3794 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3795 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3796 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3797 | if (Base.isInvalid()) |
| 3798 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3800 | NestedNameSpecifier *Qualifier = 0; |
| 3801 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3802 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3803 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 3804 | E->getQualifierRange(), |
| 3805 | false); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3806 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3807 | return SemaRef.ExprError(); |
| 3808 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3810 | ValueDecl *Member |
| 3811 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3812 | if (!Member) |
| 3813 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3815 | if (!getDerived().AlwaysRebuild() && |
| 3816 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3817 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3818 | Member == E->getMemberDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3819 | !E->hasExplicitTemplateArgumentList()) { |
| 3820 | |
| 3821 | // Mark it referenced in the new context regardless. |
| 3822 | // FIXME: this is a bit instantiation-specific. |
| 3823 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3824 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3825 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3826 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3827 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3828 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3829 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3830 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3831 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3832 | TemplateArgumentLoc Loc; |
| 3833 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3834 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3835 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3839 | // FIXME: Bogus source location for the operator |
| 3840 | SourceLocation FakeOperatorLoc |
| 3841 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3842 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3843 | // FIXME: to do this check properly, we will need to preserve the |
| 3844 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3845 | // base (and therefore couldn't do the check) and a |
| 3846 | // nested-name-qualifier (and therefore could do the lookup). |
| 3847 | NamedDecl *FirstQualifierInScope = 0; |
| 3848 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3850 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3851 | Qualifier, |
| 3852 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3853 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3854 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3855 | (E->hasExplicitTemplateArgumentList() |
| 3856 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3857 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3859 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3860 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3861 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3862 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3863 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3864 | if (LHS.isInvalid()) |
| 3865 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3867 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3868 | if (RHS.isInvalid()) |
| 3869 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3870 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3871 | if (!getDerived().AlwaysRebuild() && |
| 3872 | LHS.get() == E->getLHS() && |
| 3873 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | return SemaRef.Owned(E->Retain()); |
| 3875 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3876 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3877 | move(LHS), move(RHS)); |
| 3878 | } |
| 3879 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3880 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3881 | Sema::OwningExprResult |
| 3882 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3883 | CompoundAssignOperator *E) { |
| 3884 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3885 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3886 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3887 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3889 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3890 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3891 | if (Cond.isInvalid()) |
| 3892 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3894 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3895 | if (LHS.isInvalid()) |
| 3896 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3899 | if (RHS.isInvalid()) |
| 3900 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 3903 | Cond.get() == E->getCond() && |
| 3904 | LHS.get() == E->getLHS() && |
| 3905 | RHS.get() == E->getRHS()) |
| 3906 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | |
| 3908 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3909 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3910 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3911 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | move(RHS)); |
| 3913 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3914 | |
| 3915 | template<typename Derived> |
| 3916 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3917 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3918 | // Implicit casts are eliminated during transformation, since they |
| 3919 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3920 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3923 | template<typename Derived> |
| 3924 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3925 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3926 | TypeSourceInfo *OldT; |
| 3927 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3928 | { |
| 3929 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3930 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3931 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3932 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3933 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3934 | OldT = E->getTypeInfoAsWritten(); |
| 3935 | NewT = getDerived().TransformType(OldT); |
| 3936 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3937 | return SemaRef.ExprError(); |
| 3938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3940 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3941 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3942 | if (SubExpr.isInvalid()) |
| 3943 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3945 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3946 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3947 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3948 | return SemaRef.Owned(E->Retain()); |
| 3949 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3950 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3951 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | E->getRParenLoc(), |
| 3953 | move(SubExpr)); |
| 3954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3957 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3958 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3959 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3960 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3961 | if (!NewT) |
| 3962 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3963 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3964 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3965 | if (Init.isInvalid()) |
| 3966 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3967 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3968 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3969 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3971 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3972 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3973 | // Note: the expression type doesn't necessarily match the |
| 3974 | // type-as-written, but that's okay, because it should always be |
| 3975 | // derivable from the initializer. |
| 3976 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3977 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3978 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3979 | move(Init)); |
| 3980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3982 | template<typename Derived> |
| 3983 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3984 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3985 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3986 | if (Base.isInvalid()) |
| 3987 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | if (!getDerived().AlwaysRebuild() && |
| 3990 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | return SemaRef.Owned(E->Retain()); |
| 3992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3994 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3996 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3997 | E->getAccessorLoc(), |
| 3998 | E->getAccessor()); |
| 3999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4003 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4004 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4007 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4008 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4009 | if (Init.isInvalid()) |
| 4010 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4013 | Inits.push_back(Init.takeAs<Expr>()); |
| 4014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4016 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | return SemaRef.Owned(E->Retain()); |
| 4018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4019 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4020 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4023 | template<typename Derived> |
| 4024 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4025 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4026 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4028 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4030 | if (Init.isInvalid()) |
| 4031 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4033 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4034 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4035 | bool ExprChanged = false; |
| 4036 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4037 | DEnd = E->designators_end(); |
| 4038 | D != DEnd; ++D) { |
| 4039 | if (D->isFieldDesignator()) { |
| 4040 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4041 | D->getDotLoc(), |
| 4042 | D->getFieldLoc())); |
| 4043 | continue; |
| 4044 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | if (D->isArrayDesignator()) { |
| 4047 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4048 | if (Index.isInvalid()) |
| 4049 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4050 | |
| 4051 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4052 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4053 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4054 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4055 | ArrayExprs.push_back(Index.release()); |
| 4056 | continue; |
| 4057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4059 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4060 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4061 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4062 | if (Start.isInvalid()) |
| 4063 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4064 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4065 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4066 | if (End.isInvalid()) |
| 4067 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
| 4069 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4070 | End.get(), |
| 4071 | D->getLBracketLoc(), |
| 4072 | D->getEllipsisLoc())); |
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 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4075 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | ArrayExprs.push_back(Start.release()); |
| 4078 | ArrayExprs.push_back(End.release()); |
| 4079 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4081 | if (!getDerived().AlwaysRebuild() && |
| 4082 | Init.get() == E->getInit() && |
| 4083 | !ExprChanged) |
| 4084 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4086 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4087 | E->getEqualOrColonLoc(), |
| 4088 | E->usesGNUSyntax(), move(Init)); |
| 4089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4094 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4095 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4096 | |
| 4097 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4098 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4099 | QualType T = getDerived().TransformType(E->getType()); |
| 4100 | if (T.isNull()) |
| 4101 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4103 | if (!getDerived().AlwaysRebuild() && |
| 4104 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | return SemaRef.Owned(E->Retain()); |
| 4106 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4108 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4111 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4112 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4113 | // FIXME: Do we want the type as written? |
| 4114 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4115 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4116 | { |
| 4117 | // FIXME: Source location isn't quite accurate. |
| 4118 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4119 | T = getDerived().TransformType(E->getType()); |
| 4120 | if (T.isNull()) |
| 4121 | return SemaRef.ExprError(); |
| 4122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4125 | if (SubExpr.isInvalid()) |
| 4126 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4127 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | if (!getDerived().AlwaysRebuild() && |
| 4129 | T == E->getType() && |
| 4130 | SubExpr.get() == E->getSubExpr()) |
| 4131 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4134 | T, E->getRParenLoc()); |
| 4135 | } |
| 4136 | |
| 4137 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4139 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4140 | bool ArgumentChanged = false; |
| 4141 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4142 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4143 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4144 | if (Init.isInvalid()) |
| 4145 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4147 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4148 | Inits.push_back(Init.takeAs<Expr>()); |
| 4149 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4152 | move_arg(Inits), |
| 4153 | E->getRParenLoc()); |
| 4154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4155 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4156 | /// \brief Transform an address-of-label expression. |
| 4157 | /// |
| 4158 | /// By default, the transformation of an address-of-label expression always |
| 4159 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4160 | /// the corresponding label statement by semantic analysis. |
| 4161 | template<typename Derived> |
| 4162 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4163 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4165 | E->getLabel()); |
| 4166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4167 | |
| 4168 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4169 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4170 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4171 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4173 | if (SubStmt.isInvalid()) |
| 4174 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4176 | if (!getDerived().AlwaysRebuild() && |
| 4177 | SubStmt.get() == E->getSubStmt()) |
| 4178 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | |
| 4180 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | move(SubStmt), |
| 4182 | E->getRParenLoc()); |
| 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>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | QualType T1, T2; |
| 4189 | { |
| 4190 | // FIXME: Source location isn't quite accurate. |
| 4191 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4192 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4194 | if (T1.isNull()) |
| 4195 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4197 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4198 | if (T2.isNull()) |
| 4199 | return SemaRef.ExprError(); |
| 4200 | } |
| 4201 | |
| 4202 | if (!getDerived().AlwaysRebuild() && |
| 4203 | T1 == E->getArgType1() && |
| 4204 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | return SemaRef.Owned(E->Retain()); |
| 4206 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4208 | T1, T2, E->getRParenLoc()); |
| 4209 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | template<typename Derived> |
| 4212 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4213 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4215 | if (Cond.isInvalid()) |
| 4216 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4217 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4219 | if (LHS.isInvalid()) |
| 4220 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4223 | if (RHS.isInvalid()) |
| 4224 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4227 | Cond.get() == E->getCond() && |
| 4228 | LHS.get() == E->getLHS() && |
| 4229 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | return SemaRef.Owned(E->Retain()); |
| 4231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4233 | move(Cond), move(LHS), move(RHS), |
| 4234 | E->getRParenLoc()); |
| 4235 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4239 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | template<typename Derived> |
| 4244 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4245 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4246 | switch (E->getOperator()) { |
| 4247 | case OO_New: |
| 4248 | case OO_Delete: |
| 4249 | case OO_Array_New: |
| 4250 | case OO_Array_Delete: |
| 4251 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4252 | return SemaRef.ExprError(); |
| 4253 | |
| 4254 | case OO_Call: { |
| 4255 | // This is a call to an object's operator(). |
| 4256 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4257 | |
| 4258 | // Transform the object itself. |
| 4259 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4260 | if (Object.isInvalid()) |
| 4261 | return SemaRef.ExprError(); |
| 4262 | |
| 4263 | // FIXME: Poor location information |
| 4264 | SourceLocation FakeLParenLoc |
| 4265 | = SemaRef.PP.getLocForEndOfToken( |
| 4266 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4267 | |
| 4268 | // Transform the call arguments. |
| 4269 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4270 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4271 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4272 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4273 | break; |
| 4274 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4275 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4276 | if (Arg.isInvalid()) |
| 4277 | return SemaRef.ExprError(); |
| 4278 | |
| 4279 | // FIXME: Poor source location information. |
| 4280 | SourceLocation FakeCommaLoc |
| 4281 | = SemaRef.PP.getLocForEndOfToken( |
| 4282 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4283 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4284 | Args.push_back(Arg.release()); |
| 4285 | } |
| 4286 | |
| 4287 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4288 | move_arg(Args), |
| 4289 | FakeCommaLocs.data(), |
| 4290 | E->getLocEnd()); |
| 4291 | } |
| 4292 | |
| 4293 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4294 | case OO_##Name: |
| 4295 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4296 | #include "clang/Basic/OperatorKinds.def" |
| 4297 | case OO_Subscript: |
| 4298 | // Handled below. |
| 4299 | break; |
| 4300 | |
| 4301 | case OO_Conditional: |
| 4302 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4303 | return SemaRef.ExprError(); |
| 4304 | |
| 4305 | case OO_None: |
| 4306 | case NUM_OVERLOADED_OPERATORS: |
| 4307 | llvm_unreachable("not an overloaded operator?"); |
| 4308 | return SemaRef.ExprError(); |
| 4309 | } |
| 4310 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4312 | if (Callee.isInvalid()) |
| 4313 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4315 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4316 | if (First.isInvalid()) |
| 4317 | return SemaRef.ExprError(); |
| 4318 | |
| 4319 | OwningExprResult Second(SemaRef); |
| 4320 | if (E->getNumArgs() == 2) { |
| 4321 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4322 | if (Second.isInvalid()) |
| 4323 | return SemaRef.ExprError(); |
| 4324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | if (!getDerived().AlwaysRebuild() && |
| 4327 | Callee.get() == E->getCallee() && |
| 4328 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4330 | return SemaRef.Owned(E->Retain()); |
| 4331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4332 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4333 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4335 | move(First), |
| 4336 | move(Second)); |
| 4337 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4338 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | template<typename Derived> |
| 4340 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4341 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4342 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4345 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4346 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4347 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4348 | TypeSourceInfo *OldT; |
| 4349 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | { |
| 4351 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4353 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4354 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4356 | OldT = E->getTypeInfoAsWritten(); |
| 4357 | NewT = getDerived().TransformType(OldT); |
| 4358 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | return SemaRef.ExprError(); |
| 4360 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4361 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4362 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4363 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4364 | if (SubExpr.isInvalid()) |
| 4365 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4368 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4369 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | return SemaRef.Owned(E->Retain()); |
| 4371 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4375 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4376 | SourceLocation FakeRParenLoc |
| 4377 | = SemaRef.PP.getLocForEndOfToken( |
| 4378 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4379 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4380 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4381 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4382 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4383 | FakeRAngleLoc, |
| 4384 | FakeRAngleLoc, |
| 4385 | move(SubExpr), |
| 4386 | FakeRParenLoc); |
| 4387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | template<typename Derived> |
| 4390 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4391 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4392 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4393 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | |
| 4395 | template<typename Derived> |
| 4396 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4397 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4398 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4401 | template<typename Derived> |
| 4402 | Sema::OwningExprResult |
| 4403 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4404 | CXXReinterpretCastExpr *E) { |
| 4405 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | template<typename Derived> |
| 4409 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4410 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4411 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 |
| 4416 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4417 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4418 | TypeSourceInfo *OldT; |
| 4419 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4420 | { |
| 4421 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4423 | OldT = E->getTypeInfoAsWritten(); |
| 4424 | NewT = getDerived().TransformType(OldT); |
| 4425 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4426 | return SemaRef.ExprError(); |
| 4427 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4429 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4430 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | if (SubExpr.isInvalid()) |
| 4432 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4434 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4435 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4436 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | return SemaRef.Owned(E->Retain()); |
| 4438 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4439 | // FIXME: The end of the type's source range is wrong |
| 4440 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4441 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4442 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4444 | move(SubExpr), |
| 4445 | E->getRParenLoc()); |
| 4446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | template<typename Derived> |
| 4449 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4450 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4451 | if (E->isTypeOperand()) { |
| 4452 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4453 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4454 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4455 | if (T.isNull()) |
| 4456 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4458 | if (!getDerived().AlwaysRebuild() && |
| 4459 | T == E->getTypeOperand()) |
| 4460 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4462 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4463 | /*FIXME:*/E->getLocStart(), |
| 4464 | T, |
| 4465 | E->getLocEnd()); |
| 4466 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | // We don't know whether the expression is potentially evaluated until |
| 4469 | // after we perform semantic analysis, so the expression is potentially |
| 4470 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4474 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4475 | if (SubExpr.isInvalid()) |
| 4476 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4477 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4478 | if (!getDerived().AlwaysRebuild() && |
| 4479 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4480 | return SemaRef.Owned(E->Retain()); |
| 4481 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4483 | /*FIXME:*/E->getLocStart(), |
| 4484 | move(SubExpr), |
| 4485 | E->getLocEnd()); |
| 4486 | } |
| 4487 | |
| 4488 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4489 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4490 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4491 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4493 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4494 | template<typename Derived> |
| 4495 | Sema::OwningExprResult |
| 4496 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4497 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4498 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | template<typename Derived> |
| 4502 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4503 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4504 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | QualType T = getDerived().TransformType(E->getType()); |
| 4507 | if (T.isNull()) |
| 4508 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4509 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4510 | if (!getDerived().AlwaysRebuild() && |
| 4511 | T == E->getType()) |
| 4512 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4514 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4515 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4516 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4517 | template<typename Derived> |
| 4518 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4519 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4521 | if (SubExpr.isInvalid()) |
| 4522 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | if (!getDerived().AlwaysRebuild() && |
| 4525 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4526 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4527 | |
| 4528 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4530 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4531 | template<typename Derived> |
| 4532 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4533 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4534 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4535 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4536 | if (!Param) |
| 4537 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4539 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | Param == E->getParam()) |
| 4541 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4543 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | template<typename Derived> |
| 4547 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4548 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4550 | |
| 4551 | QualType T = getDerived().TransformType(E->getType()); |
| 4552 | if (T.isNull()) |
| 4553 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | if (!getDerived().AlwaysRebuild() && |
| 4556 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4557 | return SemaRef.Owned(E->Retain()); |
| 4558 | |
| 4559 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4560 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4561 | T, |
| 4562 | E->getRParenLoc()); |
| 4563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | template<typename Derived> |
| 4566 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4567 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4568 | // Transform the type that we're allocating |
| 4569 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4570 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4571 | if (AllocType.isNull()) |
| 4572 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | // Transform the size of the array we're allocating (if any). |
| 4575 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4576 | if (ArraySize.isInvalid()) |
| 4577 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | // Transform the placement arguments (if any). |
| 4580 | bool ArgumentChanged = false; |
| 4581 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4582 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4583 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4584 | if (Arg.isInvalid()) |
| 4585 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4586 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4587 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4588 | PlacementArgs.push_back(Arg.take()); |
| 4589 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4590 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4591 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4592 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4593 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4594 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4595 | if (Arg.isInvalid()) |
| 4596 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4597 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4598 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4599 | ConstructorArgs.push_back(Arg.take()); |
| 4600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4602 | if (!getDerived().AlwaysRebuild() && |
| 4603 | AllocType == E->getAllocatedType() && |
| 4604 | ArraySize.get() == E->getArraySize() && |
| 4605 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | return SemaRef.Owned(E->Retain()); |
| 4607 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4608 | if (!ArraySize.get()) { |
| 4609 | // If no array size was specified, but the new expression was |
| 4610 | // instantiated with an array type (e.g., "new T" where T is |
| 4611 | // instantiated with "int[4]"), extract the outer bound from the |
| 4612 | // array type as our array size. We do this with constant and |
| 4613 | // dependently-sized array types. |
| 4614 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4615 | if (!ArrayT) { |
| 4616 | // Do nothing |
| 4617 | } else if (const ConstantArrayType *ConsArrayT |
| 4618 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4619 | ArraySize |
| 4620 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4621 | ConsArrayT->getSize(), |
| 4622 | SemaRef.Context.getSizeType(), |
| 4623 | /*FIXME:*/E->getLocStart())); |
| 4624 | AllocType = ConsArrayT->getElementType(); |
| 4625 | } else if (const DependentSizedArrayType *DepArrayT |
| 4626 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4627 | if (DepArrayT->getSizeExpr()) { |
| 4628 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4629 | AllocType = DepArrayT->getElementType(); |
| 4630 | } |
| 4631 | } |
| 4632 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4634 | E->isGlobalNew(), |
| 4635 | /*FIXME:*/E->getLocStart(), |
| 4636 | move_arg(PlacementArgs), |
| 4637 | /*FIXME:*/E->getLocStart(), |
| 4638 | E->isParenTypeId(), |
| 4639 | AllocType, |
| 4640 | /*FIXME:*/E->getLocStart(), |
| 4641 | /*FIXME:*/SourceRange(), |
| 4642 | move(ArraySize), |
| 4643 | /*FIXME:*/E->getLocStart(), |
| 4644 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4648 | template<typename Derived> |
| 4649 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4650 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4652 | if (Operand.isInvalid()) |
| 4653 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4654 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4655 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | Operand.get() == E->getArgument()) |
| 4657 | return SemaRef.Owned(E->Retain()); |
| 4658 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4660 | E->isGlobalDelete(), |
| 4661 | E->isArrayForm(), |
| 4662 | move(Operand)); |
| 4663 | } |
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 | template<typename Derived> |
| 4666 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4667 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4668 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4669 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4670 | if (Base.isInvalid()) |
| 4671 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4673 | NestedNameSpecifier *Qualifier |
| 4674 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4675 | E->getQualifierRange(), |
| 4676 | true); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4677 | if (E->getQualifier() && !Qualifier) |
| 4678 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame^] | 4680 | // FIXME: Object type! |
| 4681 | TypeSourceInfo *DestroyedTypeInfo |
| 4682 | = getDerived().TransformType(E->getDestroyedTypeInfo()); |
| 4683 | if (!DestroyedTypeInfo) |
| 4684 | return SemaRef.ExprError(); |
| 4685 | |
| 4686 | // FIXME: Object type! |
| 4687 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 4688 | if (E->getScopeTypeInfo()) { |
| 4689 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); |
| 4690 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4691 | return SemaRef.ExprError(); |
| 4692 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame^] | 4693 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4694 | if (!getDerived().AlwaysRebuild() && |
| 4695 | Base.get() == E->getBase() && |
| 4696 | Qualifier == E->getQualifier() && |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame^] | 4697 | ScopeTypeInfo == E->getScopeTypeInfo() && |
| 4698 | DestroyedTypeInfo == E->getDestroyedTypeInfo()) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4699 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4701 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4702 | E->getOperatorLoc(), |
| 4703 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4704 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame^] | 4705 | E->getQualifierRange(), |
| 4706 | ScopeTypeInfo, |
| 4707 | E->getColonColonLoc(), |
| 4708 | DestroyedTypeInfo); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4710 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4711 | template<typename Derived> |
| 4712 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4713 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4714 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4715 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4716 | |
| 4717 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4718 | Sema::LookupOrdinaryName); |
| 4719 | |
| 4720 | // Transform all the decls. |
| 4721 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4722 | E = Old->decls_end(); I != E; ++I) { |
| 4723 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4724 | if (!InstD) { |
| 4725 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4726 | // This can happen because of dependent hiding. |
| 4727 | if (isa<UsingShadowDecl>(*I)) |
| 4728 | continue; |
| 4729 | else |
| 4730 | return SemaRef.ExprError(); |
| 4731 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4732 | |
| 4733 | // Expand using declarations. |
| 4734 | if (isa<UsingDecl>(InstD)) { |
| 4735 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4736 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4737 | E = UD->shadow_end(); I != E; ++I) |
| 4738 | R.addDecl(*I); |
| 4739 | continue; |
| 4740 | } |
| 4741 | |
| 4742 | R.addDecl(InstD); |
| 4743 | } |
| 4744 | |
| 4745 | // Resolve a kind, but don't do any further analysis. If it's |
| 4746 | // ambiguous, the callee needs to deal with it. |
| 4747 | R.resolveKind(); |
| 4748 | |
| 4749 | // Rebuild the nested-name qualifier, if present. |
| 4750 | CXXScopeSpec SS; |
| 4751 | NestedNameSpecifier *Qualifier = 0; |
| 4752 | if (Old->getQualifier()) { |
| 4753 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4754 | Old->getQualifierRange(), |
| 4755 | false); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4756 | if (!Qualifier) |
| 4757 | return SemaRef.ExprError(); |
| 4758 | |
| 4759 | SS.setScopeRep(Qualifier); |
| 4760 | SS.setRange(Old->getQualifierRange()); |
| 4761 | } |
| 4762 | |
| 4763 | // If we have no template arguments, it's a normal declaration name. |
| 4764 | if (!Old->hasExplicitTemplateArgs()) |
| 4765 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4766 | |
| 4767 | // If we have template arguments, rebuild them, then rebuild the |
| 4768 | // templateid expression. |
| 4769 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4770 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4771 | TemplateArgumentLoc Loc; |
| 4772 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4773 | return SemaRef.ExprError(); |
| 4774 | TransArgs.addArgument(Loc); |
| 4775 | } |
| 4776 | |
| 4777 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4778 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4780 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4781 | template<typename Derived> |
| 4782 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4783 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4785 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4786 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4787 | if (T.isNull()) |
| 4788 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4790 | if (!getDerived().AlwaysRebuild() && |
| 4791 | T == E->getQueriedType()) |
| 4792 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4793 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | // FIXME: Bad location information |
| 4795 | SourceLocation FakeLParenLoc |
| 4796 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | |
| 4798 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | E->getLocStart(), |
| 4800 | /*FIXME:*/FakeLParenLoc, |
| 4801 | T, |
| 4802 | E->getLocEnd()); |
| 4803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4805 | template<typename Derived> |
| 4806 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4807 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4808 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4809 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4810 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 4811 | E->getQualifierRange(), |
| 4812 | false); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4813 | if (!NNS) |
| 4814 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4815 | |
| 4816 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4817 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4818 | if (!Name) |
| 4819 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4821 | if (!E->hasExplicitTemplateArgs()) { |
| 4822 | if (!getDerived().AlwaysRebuild() && |
| 4823 | NNS == E->getQualifier() && |
| 4824 | Name == E->getDeclName()) |
| 4825 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4826 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4827 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4828 | E->getQualifierRange(), |
| 4829 | Name, E->getLocation(), |
| 4830 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4831 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4832 | |
| 4833 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4835 | TemplateArgumentLoc Loc; |
| 4836 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4837 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4838 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4841 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4842 | E->getQualifierRange(), |
| 4843 | Name, E->getLocation(), |
| 4844 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | template<typename Derived> |
| 4848 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4849 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4850 | // CXXConstructExprs are always implicit, so when we have a |
| 4851 | // 1-argument construction we just transform that argument. |
| 4852 | if (E->getNumArgs() == 1 || |
| 4853 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 4854 | return getDerived().TransformExpr(E->getArg(0)); |
| 4855 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4856 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4857 | |
| 4858 | QualType T = getDerived().TransformType(E->getType()); |
| 4859 | if (T.isNull()) |
| 4860 | return SemaRef.ExprError(); |
| 4861 | |
| 4862 | CXXConstructorDecl *Constructor |
| 4863 | = cast_or_null<CXXConstructorDecl>( |
| 4864 | getDerived().TransformDecl(E->getConstructor())); |
| 4865 | if (!Constructor) |
| 4866 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4867 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4868 | bool ArgumentChanged = false; |
| 4869 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4870 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4871 | ArgEnd = E->arg_end(); |
| 4872 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4873 | if (getDerived().DropCallArgument(*Arg)) { |
| 4874 | ArgumentChanged = true; |
| 4875 | break; |
| 4876 | } |
| 4877 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4879 | if (TransArg.isInvalid()) |
| 4880 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4881 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4882 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4883 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4884 | } |
| 4885 | |
| 4886 | if (!getDerived().AlwaysRebuild() && |
| 4887 | T == E->getType() && |
| 4888 | Constructor == E->getConstructor() && |
| 4889 | !ArgumentChanged) |
| 4890 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4891 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4892 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4893 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | move_arg(Args)); |
| 4895 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4896 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4897 | /// \brief Transform a C++ temporary-binding expression. |
| 4898 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4899 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4900 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4901 | template<typename Derived> |
| 4902 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4903 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4904 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4906 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 4907 | /// \brief Transform a C++ reference-binding expression. |
| 4908 | /// |
| 4909 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 4910 | /// transform the subexpression and return that. |
| 4911 | template<typename Derived> |
| 4912 | Sema::OwningExprResult |
| 4913 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 4914 | return getDerived().TransformExpr(E->getSubExpr()); |
| 4915 | } |
| 4916 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4917 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4918 | /// be destroyed after the expression is evaluated. |
| 4919 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4920 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4921 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4922 | template<typename Derived> |
| 4923 | Sema::OwningExprResult |
| 4924 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4925 | CXXExprWithTemporaries *E) { |
| 4926 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4927 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4928 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4929 | template<typename Derived> |
| 4930 | Sema::OwningExprResult |
| 4931 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4932 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4933 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4934 | QualType T = getDerived().TransformType(E->getType()); |
| 4935 | if (T.isNull()) |
| 4936 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4938 | CXXConstructorDecl *Constructor |
| 4939 | = cast_or_null<CXXConstructorDecl>( |
| 4940 | getDerived().TransformDecl(E->getConstructor())); |
| 4941 | if (!Constructor) |
| 4942 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4943 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4944 | bool ArgumentChanged = false; |
| 4945 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4946 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4947 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | ArgEnd = E->arg_end(); |
| 4949 | Arg != ArgEnd; ++Arg) { |
| 4950 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4951 | if (TransArg.isInvalid()) |
| 4952 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4953 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4954 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4955 | Args.push_back((Expr *)TransArg.release()); |
| 4956 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4958 | if (!getDerived().AlwaysRebuild() && |
| 4959 | T == E->getType() && |
| 4960 | Constructor == E->getConstructor() && |
| 4961 | !ArgumentChanged) |
| 4962 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4963 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4964 | // FIXME: Bogus location information |
| 4965 | SourceLocation CommaLoc; |
| 4966 | if (Args.size() > 1) { |
| 4967 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4969 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4970 | } |
| 4971 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4972 | T, |
| 4973 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4974 | move_arg(Args), |
| 4975 | &CommaLoc, |
| 4976 | E->getLocEnd()); |
| 4977 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4979 | template<typename Derived> |
| 4980 | Sema::OwningExprResult |
| 4981 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4982 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4983 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4984 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4985 | if (T.isNull()) |
| 4986 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4988 | bool ArgumentChanged = false; |
| 4989 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4990 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4991 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4992 | ArgEnd = E->arg_end(); |
| 4993 | Arg != ArgEnd; ++Arg) { |
| 4994 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4995 | if (TransArg.isInvalid()) |
| 4996 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4997 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4998 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4999 | FakeCommaLocs.push_back( |
| 5000 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5001 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5002 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5003 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5004 | if (!getDerived().AlwaysRebuild() && |
| 5005 | T == E->getTypeAsWritten() && |
| 5006 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5007 | return SemaRef.Owned(E->Retain()); |
| 5008 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5009 | // FIXME: we're faking the locations of the commas |
| 5010 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5011 | T, |
| 5012 | E->getLParenLoc(), |
| 5013 | move_arg(Args), |
| 5014 | FakeCommaLocs.data(), |
| 5015 | E->getRParenLoc()); |
| 5016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5018 | template<typename Derived> |
| 5019 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5020 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5021 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5022 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5023 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5024 | Expr *OldBase; |
| 5025 | QualType BaseType; |
| 5026 | QualType ObjectType; |
| 5027 | if (!E->isImplicitAccess()) { |
| 5028 | OldBase = E->getBase(); |
| 5029 | Base = getDerived().TransformExpr(OldBase); |
| 5030 | if (Base.isInvalid()) |
| 5031 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5032 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5033 | // Start the member reference and compute the object's type. |
| 5034 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5035 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5036 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5037 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5038 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5039 | ObjectTy, |
| 5040 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5041 | if (Base.isInvalid()) |
| 5042 | return SemaRef.ExprError(); |
| 5043 | |
| 5044 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5045 | BaseType = ((Expr*) Base.get())->getType(); |
| 5046 | } else { |
| 5047 | OldBase = 0; |
| 5048 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5049 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5052 | // Transform the first part of the nested-name-specifier that qualifies |
| 5053 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5054 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5055 | = getDerived().TransformFirstQualifierInScope( |
| 5056 | E->getFirstQualifierFoundInScope(), |
| 5057 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5058 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5059 | NestedNameSpecifier *Qualifier = 0; |
| 5060 | if (E->getQualifier()) { |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5061 | bool MayBePseudoDestructor |
| 5062 | = E->getMember().getNameKind() == DeclarationName::CXXDestructorName; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5063 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5064 | E->getQualifierRange(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5065 | MayBePseudoDestructor, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5066 | ObjectType, |
| 5067 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5068 | if (!Qualifier) |
| 5069 | return SemaRef.ExprError(); |
| 5070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5071 | |
| 5072 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5073 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5074 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5075 | if (!Name) |
| 5076 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5078 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5079 | // This is a reference to a member without an explicitly-specified |
| 5080 | // template argument list. Optimize for this common case. |
| 5081 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5082 | Base.get() == OldBase && |
| 5083 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5084 | Qualifier == E->getQualifier() && |
| 5085 | Name == E->getMember() && |
| 5086 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | return SemaRef.Owned(E->Retain()); |
| 5088 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5089 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5090 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5091 | E->isArrow(), |
| 5092 | E->getOperatorLoc(), |
| 5093 | Qualifier, |
| 5094 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5095 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5096 | Name, |
| 5097 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5098 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5101 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5102 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5103 | TemplateArgumentLoc Loc; |
| 5104 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5105 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5106 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5107 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5108 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5109 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5110 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5111 | E->isArrow(), |
| 5112 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5113 | Qualifier, |
| 5114 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5115 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5116 | Name, |
| 5117 | E->getMemberLoc(), |
| 5118 | &TransArgs); |
| 5119 | } |
| 5120 | |
| 5121 | template<typename Derived> |
| 5122 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5123 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5124 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5125 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5126 | QualType BaseType; |
| 5127 | if (!Old->isImplicitAccess()) { |
| 5128 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5129 | if (Base.isInvalid()) |
| 5130 | return SemaRef.ExprError(); |
| 5131 | BaseType = ((Expr*) Base.get())->getType(); |
| 5132 | } else { |
| 5133 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5134 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5135 | |
| 5136 | NestedNameSpecifier *Qualifier = 0; |
| 5137 | if (Old->getQualifier()) { |
| 5138 | Qualifier |
| 5139 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5140 | Old->getQualifierRange(), |
| 5141 | false); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5142 | if (Qualifier == 0) |
| 5143 | return SemaRef.ExprError(); |
| 5144 | } |
| 5145 | |
| 5146 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5147 | Sema::LookupOrdinaryName); |
| 5148 | |
| 5149 | // Transform all the decls. |
| 5150 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5151 | E = Old->decls_end(); I != E; ++I) { |
| 5152 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5153 | if (!InstD) { |
| 5154 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5155 | // This can happen because of dependent hiding. |
| 5156 | if (isa<UsingShadowDecl>(*I)) |
| 5157 | continue; |
| 5158 | else |
| 5159 | return SemaRef.ExprError(); |
| 5160 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5161 | |
| 5162 | // Expand using declarations. |
| 5163 | if (isa<UsingDecl>(InstD)) { |
| 5164 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5165 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5166 | E = UD->shadow_end(); I != E; ++I) |
| 5167 | R.addDecl(*I); |
| 5168 | continue; |
| 5169 | } |
| 5170 | |
| 5171 | R.addDecl(InstD); |
| 5172 | } |
| 5173 | |
| 5174 | R.resolveKind(); |
| 5175 | |
| 5176 | TemplateArgumentListInfo TransArgs; |
| 5177 | if (Old->hasExplicitTemplateArgs()) { |
| 5178 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5179 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5180 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5181 | TemplateArgumentLoc Loc; |
| 5182 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5183 | Loc)) |
| 5184 | return SemaRef.ExprError(); |
| 5185 | TransArgs.addArgument(Loc); |
| 5186 | } |
| 5187 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5188 | |
| 5189 | // FIXME: to do this check properly, we will need to preserve the |
| 5190 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5191 | // base (and therefore couldn't do the check) and a |
| 5192 | // nested-name-qualifier (and therefore could do the lookup). |
| 5193 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5194 | |
| 5195 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5196 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5197 | Old->getOperatorLoc(), |
| 5198 | Old->isArrow(), |
| 5199 | Qualifier, |
| 5200 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5201 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5202 | R, |
| 5203 | (Old->hasExplicitTemplateArgs() |
| 5204 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | template<typename Derived> |
| 5208 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5209 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5213 | template<typename Derived> |
| 5214 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5215 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5216 | // FIXME: poor source location |
| 5217 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5218 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5219 | if (EncodedType.isNull()) |
| 5220 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5222 | if (!getDerived().AlwaysRebuild() && |
| 5223 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5224 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5225 | |
| 5226 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5227 | EncodedType, |
| 5228 | E->getRParenLoc()); |
| 5229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | template<typename Derived> |
| 5232 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5233 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5234 | // FIXME: Implement this! |
| 5235 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5237 | } |
| 5238 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5239 | template<typename Derived> |
| 5240 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5241 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5242 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5245 | template<typename Derived> |
| 5246 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5247 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5248 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5249 | = cast_or_null<ObjCProtocolDecl>( |
| 5250 | getDerived().TransformDecl(E->getProtocol())); |
| 5251 | if (!Protocol) |
| 5252 | return SemaRef.ExprError(); |
| 5253 | |
| 5254 | if (!getDerived().AlwaysRebuild() && |
| 5255 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5256 | return SemaRef.Owned(E->Retain()); |
| 5257 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5259 | E->getAtLoc(), |
| 5260 | /*FIXME:*/E->getAtLoc(), |
| 5261 | /*FIXME:*/E->getAtLoc(), |
| 5262 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5264 | } |
| 5265 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | template<typename Derived> |
| 5267 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5268 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5269 | // FIXME: Implement this! |
| 5270 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5272 | } |
| 5273 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5274 | template<typename Derived> |
| 5275 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5276 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5277 | // FIXME: Implement this! |
| 5278 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5279 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5280 | } |
| 5281 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5282 | template<typename Derived> |
| 5283 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5284 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5285 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5286 | // FIXME: Implement this! |
| 5287 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5288 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5289 | } |
| 5290 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5291 | template<typename Derived> |
| 5292 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5293 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5294 | // FIXME: Implement this! |
| 5295 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5296 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5299 | template<typename Derived> |
| 5300 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5301 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5302 | // FIXME: Implement this! |
| 5303 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5304 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5305 | } |
| 5306 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5307 | template<typename Derived> |
| 5308 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5309 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5310 | bool ArgumentChanged = false; |
| 5311 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5312 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5313 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5314 | if (SubExpr.isInvalid()) |
| 5315 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5317 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5318 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5319 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5320 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5321 | if (!getDerived().AlwaysRebuild() && |
| 5322 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | return SemaRef.Owned(E->Retain()); |
| 5324 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5325 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5326 | move_arg(SubExprs), |
| 5327 | E->getRParenLoc()); |
| 5328 | } |
| 5329 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5330 | template<typename Derived> |
| 5331 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5332 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5333 | // FIXME: Implement this! |
| 5334 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | template<typename Derived> |
| 5339 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5340 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5341 | // FIXME: Implement this! |
| 5342 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5343 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5344 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5346 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5347 | // Type reconstruction |
| 5348 | //===----------------------------------------------------------------------===// |
| 5349 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5351 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5352 | SourceLocation Star) { |
| 5353 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5354 | getDerived().getBaseEntity()); |
| 5355 | } |
| 5356 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5357 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5358 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5359 | SourceLocation Star) { |
| 5360 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5361 | getDerived().getBaseEntity()); |
| 5362 | } |
| 5363 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | template<typename Derived> |
| 5365 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5366 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5367 | bool WrittenAsLValue, |
| 5368 | SourceLocation Sigil) { |
| 5369 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5370 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5375 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5376 | QualType ClassType, |
| 5377 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5378 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5379 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5383 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5384 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5385 | SourceLocation Sigil) { |
| 5386 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5387 | getDerived().getBaseEntity()); |
| 5388 | } |
| 5389 | |
| 5390 | template<typename Derived> |
| 5391 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5392 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5393 | ArrayType::ArraySizeModifier SizeMod, |
| 5394 | const llvm::APInt *Size, |
| 5395 | Expr *SizeExpr, |
| 5396 | unsigned IndexTypeQuals, |
| 5397 | SourceRange BracketsRange) { |
| 5398 | if (SizeExpr || !Size) |
| 5399 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5400 | IndexTypeQuals, BracketsRange, |
| 5401 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | |
| 5403 | QualType Types[] = { |
| 5404 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5405 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5406 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5407 | }; |
| 5408 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5409 | QualType SizeType; |
| 5410 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5411 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5412 | SizeType = Types[I]; |
| 5413 | break; |
| 5414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5415 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5416 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5418 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5419 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5420 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5421 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5422 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | QualType |
| 5424 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5425 | ArrayType::ArraySizeModifier SizeMod, |
| 5426 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5427 | unsigned IndexTypeQuals, |
| 5428 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5429 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5430 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5435 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5436 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5437 | unsigned IndexTypeQuals, |
| 5438 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5439 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5440 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5441 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5442 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5443 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | QualType |
| 5445 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5446 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5447 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5448 | unsigned IndexTypeQuals, |
| 5449 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5450 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5451 | SizeExpr.takeAs<Expr>(), |
| 5452 | IndexTypeQuals, BracketsRange); |
| 5453 | } |
| 5454 | |
| 5455 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | QualType |
| 5457 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5458 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5459 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5460 | unsigned IndexTypeQuals, |
| 5461 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5463 | SizeExpr.takeAs<Expr>(), |
| 5464 | IndexTypeQuals, BracketsRange); |
| 5465 | } |
| 5466 | |
| 5467 | template<typename Derived> |
| 5468 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5469 | unsigned NumElements, |
| 5470 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5471 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5472 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5473 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5475 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5476 | template<typename Derived> |
| 5477 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5478 | unsigned NumElements, |
| 5479 | SourceLocation AttributeLoc) { |
| 5480 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5481 | NumElements, true); |
| 5482 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5483 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5484 | AttributeLoc); |
| 5485 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5486 | AttributeLoc); |
| 5487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5489 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5490 | QualType |
| 5491 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5492 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5493 | SourceLocation AttributeLoc) { |
| 5494 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5495 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5496 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5497 | template<typename Derived> |
| 5498 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5499 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5500 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5501 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5502 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5503 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5504 | Quals, |
| 5505 | getDerived().getBaseLocation(), |
| 5506 | getDerived().getBaseEntity()); |
| 5507 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5508 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5509 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5510 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5511 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5512 | } |
| 5513 | |
| 5514 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5515 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5516 | assert(D && "no decl found"); |
| 5517 | if (D->isInvalidDecl()) return QualType(); |
| 5518 | |
| 5519 | TypeDecl *Ty; |
| 5520 | if (isa<UsingDecl>(D)) { |
| 5521 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5522 | assert(Using->isTypeName() && |
| 5523 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5524 | |
| 5525 | // A valid resolved using typename decl points to exactly one type decl. |
| 5526 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5527 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5528 | |
| 5529 | } else { |
| 5530 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5531 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5532 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5533 | } |
| 5534 | |
| 5535 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5536 | } |
| 5537 | |
| 5538 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5539 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5540 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5541 | } |
| 5542 | |
| 5543 | template<typename Derived> |
| 5544 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5545 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5546 | } |
| 5547 | |
| 5548 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5549 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5550 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5551 | } |
| 5552 | |
| 5553 | template<typename Derived> |
| 5554 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5555 | TemplateName Template, |
| 5556 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5557 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5558 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5560 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5561 | template<typename Derived> |
| 5562 | NestedNameSpecifier * |
| 5563 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5564 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5565 | IdentifierInfo &II, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5566 | bool MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5567 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5568 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5569 | CXXScopeSpec SS; |
| 5570 | // FIXME: The source location information is all wrong. |
| 5571 | SS.setRange(Range); |
| 5572 | SS.setScopeRep(Prefix); |
| 5573 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5575 | Range.getEnd(), II, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5576 | MayBePseudoDestructor, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5577 | ObjectType, |
| 5578 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5579 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5580 | } |
| 5581 | |
| 5582 | template<typename Derived> |
| 5583 | NestedNameSpecifier * |
| 5584 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5585 | SourceRange Range, |
| 5586 | NamespaceDecl *NS) { |
| 5587 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5588 | } |
| 5589 | |
| 5590 | template<typename Derived> |
| 5591 | NestedNameSpecifier * |
| 5592 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5593 | SourceRange Range, |
| 5594 | bool TemplateKW, |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5595 | QualType T, |
| 5596 | bool MayBePseudoDestructor) { |
| 5597 | if (MayBePseudoDestructor || T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5598 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5599 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5600 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5601 | T.getTypePtr()); |
| 5602 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5604 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5605 | return 0; |
| 5606 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5608 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5610 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5611 | bool TemplateKW, |
| 5612 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5613 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5614 | Template); |
| 5615 | } |
| 5616 | |
| 5617 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5618 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5619 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5620 | const IdentifierInfo &II, |
| 5621 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5622 | CXXScopeSpec SS; |
| 5623 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5624 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5625 | UnqualifiedId Name; |
| 5626 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5627 | return getSema().ActOnDependentTemplateName( |
| 5628 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5629 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5630 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5631 | ObjectType.getAsOpaquePtr(), |
| 5632 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5633 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5636 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5637 | TemplateName |
| 5638 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5639 | OverloadedOperatorKind Operator, |
| 5640 | QualType ObjectType) { |
| 5641 | CXXScopeSpec SS; |
| 5642 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5643 | SS.setScopeRep(Qualifier); |
| 5644 | UnqualifiedId Name; |
| 5645 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5646 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5647 | Operator, SymbolLocations); |
| 5648 | return getSema().ActOnDependentTemplateName( |
| 5649 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5650 | SS, |
| 5651 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5652 | ObjectType.getAsOpaquePtr(), |
| 5653 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5654 | .template getAsVal<TemplateName>(); |
| 5655 | } |
| 5656 | |
| 5657 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5659 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5660 | SourceLocation OpLoc, |
| 5661 | ExprArg Callee, |
| 5662 | ExprArg First, |
| 5663 | ExprArg Second) { |
| 5664 | Expr *FirstExpr = (Expr *)First.get(); |
| 5665 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5666 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5667 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5669 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5670 | if (Op == OO_Subscript) { |
| 5671 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5672 | !SecondExpr->getType()->isOverloadableType()) |
| 5673 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5674 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5675 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5676 | } else if (Op == OO_Arrow) { |
| 5677 | // -> is never a builtin operation. |
| 5678 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5679 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5680 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5681 | // The argument is not of overloadable type, so try to create a |
| 5682 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5683 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5685 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5687 | } |
| 5688 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | !SecondExpr->getType()->isOverloadableType()) { |
| 5691 | // Neither of the arguments is an overloadable type, so try to |
| 5692 | // create a built-in binary operation. |
| 5693 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5694 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5695 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5696 | if (Result.isInvalid()) |
| 5697 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5698 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5699 | First.release(); |
| 5700 | Second.release(); |
| 5701 | return move(Result); |
| 5702 | } |
| 5703 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5704 | |
| 5705 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5706 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5707 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5708 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5709 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5710 | assert(ULE->requiresADL()); |
| 5711 | |
| 5712 | // FIXME: Do we have to check |
| 5713 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5714 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5715 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5716 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5717 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5718 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5719 | // Add any functions found via argument-dependent lookup. |
| 5720 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5721 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5722 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5723 | // Create the overloaded operator invocation for unary operators. |
| 5724 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5725 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5726 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5727 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5728 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5730 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5731 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5732 | OpLoc, |
| 5733 | move(First), |
| 5734 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5736 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5737 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5738 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5739 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5740 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5741 | if (Result.isInvalid()) |
| 5742 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5743 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5744 | First.release(); |
| 5745 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5746 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5748 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame^] | 5749 | template<typename Derived> |
| 5750 | Sema::OwningExprResult |
| 5751 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 5752 | SourceLocation OperatorLoc, |
| 5753 | bool isArrow, |
| 5754 | NestedNameSpecifier *Qualifier, |
| 5755 | SourceRange QualifierRange, |
| 5756 | TypeSourceInfo *ScopeType, |
| 5757 | SourceLocation CCLoc, |
| 5758 | TypeSourceInfo *DestroyedType) { |
| 5759 | CXXScopeSpec SS; |
| 5760 | if (Qualifier) { |
| 5761 | SS.setRange(QualifierRange); |
| 5762 | SS.setScopeRep(Qualifier); |
| 5763 | } |
| 5764 | |
| 5765 | Expr *BaseE = (Expr *)Base.get(); |
| 5766 | QualType BaseType = BaseE->getType(); |
| 5767 | if (BaseE->isTypeDependent() || |
| 5768 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 5769 | (isArrow && BaseType->getAs<PointerType>() && |
| 5770 | !BaseType->getAs<PointerType>()->getAs<RecordType>())) { |
| 5771 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 5772 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 5773 | isArrow? tok::arrow : tok::period, |
| 5774 | SS, ScopeType, CCLoc, |
| 5775 | DestroyedType, |
| 5776 | /*FIXME?*/true); |
| 5777 | } |
| 5778 | |
| 5779 | DeclarationName Name |
| 5780 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 5781 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
| 5782 | |
| 5783 | // FIXME: the ScopeType should be tacked onto SS. |
| 5784 | |
| 5785 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 5786 | OperatorLoc, isArrow, |
| 5787 | SS, /*FIXME: FirstQualifier*/ 0, |
| 5788 | Name, |
| 5789 | DestroyedType->getTypeLoc().getSourceRange().getBegin(), |
| 5790 | /*TemplateArgs*/ 0); |
| 5791 | } |
| 5792 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5793 | } // end namespace clang |
| 5794 | |
| 5795 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |