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; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 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 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 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. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 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 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 212 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 217 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 218 | /// statement or the TransformExpr() function to transform an expression. |
| 219 | /// Subclasses may override this function to transform statements using some |
| 220 | /// other mechanism. |
| 221 | /// |
| 222 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 227 | /// By default, this routine transforms an expression by delegating to the |
| 228 | /// appropriate TransformXXXExpr function to build a new expression. |
| 229 | /// Subclasses may override this function to transform expressions using some |
| 230 | /// other mechanism. |
| 231 | /// |
| 232 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 235 | /// \brief Transform the given declaration, which is referenced from a type |
| 236 | /// or expression. |
| 237 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 238 | /// By default, acts as the identity function on declarations. Subclasses |
| 239 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 240 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 246 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 247 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 250 | /// \brief Transform the given declaration, which was the first part of a |
| 251 | /// nested-name-specifier in a member access expression. |
| 252 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 253 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 254 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 255 | /// the \c T in \c x->T::member |
| 256 | /// |
| 257 | /// By default, invokes TransformDecl() to transform the declaration. |
| 258 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 259 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 260 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 261 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 263 | /// \brief Transform the given nested-name-specifier. |
| 264 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 266 | /// nested-name-specifier. Subclasses may override this function to provide |
| 267 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 268 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 269 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 270 | QualType ObjectType = QualType(), |
| 271 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 273 | /// \brief Transform the given declaration name. |
| 274 | /// |
| 275 | /// By default, transforms the types of conversion function, constructor, |
| 276 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 277 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 278 | /// override this function to provide alternate behavior. |
| 279 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 280 | SourceLocation Loc, |
| 281 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 283 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 287 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 288 | TemplateName TransformTemplateName(TemplateName Name, |
| 289 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// \brief Transform the given template argument. |
| 292 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | /// By default, this operation transforms the type, expression, or |
| 294 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 295 | /// new template argument from the transformed result. Subclasses may |
| 296 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 297 | /// |
| 298 | /// Returns true if there was an error. |
| 299 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 300 | TemplateArgumentLoc &Output); |
| 301 | |
| 302 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 303 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 304 | TemplateArgumentLoc &ArgLoc); |
| 305 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 306 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 307 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 308 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 309 | getDerived().getBaseLocation()); |
| 310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 312 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 313 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 314 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 315 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 316 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 317 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 318 | /// \brief Transforms the parameters of a function type into the |
| 319 | /// given vectors. |
| 320 | /// |
| 321 | /// The result vectors should be kept in sync; null entries in the |
| 322 | /// variables vector are acceptable. |
| 323 | /// |
| 324 | /// Return true on error. |
| 325 | bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 326 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 327 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars); |
| 328 | |
| 329 | /// \brief Transforms a single function-type parameter. Return null |
| 330 | /// on error. |
| 331 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); |
| 332 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 333 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 334 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 335 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 336 | QualType |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 337 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 338 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 340 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | 105dfb5 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 341 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 343 | #define STMT(Node, Parent) \ |
| 344 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 345 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 346 | OwningExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 347 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 348 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// \brief Build a new pointer type given its pointee type. |
| 351 | /// |
| 352 | /// By default, performs semantic analysis when building the pointer type. |
| 353 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 354 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | |
| 356 | /// \brief Build a new block pointer type given its pointee type. |
| 357 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 360 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 363 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | /// By default, performs semantic analysis when building the |
| 365 | /// reference type. Subclasses may override this routine to provide |
| 366 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 367 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | /// \param LValue whether the type was written with an lvalue sigil |
| 369 | /// or an rvalue sigil. |
| 370 | QualType RebuildReferenceType(QualType ReferentType, |
| 371 | bool LValue, |
| 372 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 374 | /// \brief Build a new member pointer type given the pointee type and the |
| 375 | /// class type it refers into. |
| 376 | /// |
| 377 | /// By default, performs semantic analysis when building the member pointer |
| 378 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 379 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 380 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | /// \brief Build a new array type given the element type, size |
| 383 | /// modifier, size of the array (if known), size expression, and index type |
| 384 | /// qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | QualType RebuildArrayType(QualType ElementType, |
| 390 | ArrayType::ArraySizeModifier SizeMod, |
| 391 | const llvm::APInt *Size, |
| 392 | Expr *SizeExpr, |
| 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new constant array type given the element type, size |
| 397 | /// modifier, (known) size of the array, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
| 403 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 404 | unsigned IndexTypeQuals, |
| 405 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// \brief Build a new incomplete array type given the element type, size |
| 408 | /// modifier, and index type qualifiers. |
| 409 | /// |
| 410 | /// By default, performs semantic analysis when building the array type. |
| 411 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 413 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 429 | /// size modifier, size expression, and index type qualifiers. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the array type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | unsigned IndexTypeQuals, |
| 437 | SourceRange BracketsRange); |
| 438 | |
| 439 | /// \brief Build a new vector type given the element type and |
| 440 | /// number of elements. |
| 441 | /// |
| 442 | /// By default, performs semantic analysis when building the vector type. |
| 443 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 444 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 445 | VectorType::AltiVecSpecific AltiVecSpec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Build a new extended vector type given the element type and |
| 448 | /// number of elements. |
| 449 | /// |
| 450 | /// By default, performs semantic analysis when building the vector type. |
| 451 | /// Subclasses may override this routine to provide different behavior. |
| 452 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 453 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// given the element type and number of elements. |
| 457 | /// |
| 458 | /// By default, performs semantic analysis when building the vector type. |
| 459 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new function type. |
| 465 | /// |
| 466 | /// By default, performs semantic analysis when building the function type. |
| 467 | /// Subclasses may override this routine to provide different behavior. |
| 468 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 471 | bool Variadic, unsigned Quals, |
| 472 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 473 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 474 | /// \brief Build a new unprototyped function type. |
| 475 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 476 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 477 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 478 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 479 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 480 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 481 | /// \brief Build a new typedef type. |
| 482 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 483 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 484 | } |
| 485 | |
| 486 | /// \brief Build a new class/struct/union type. |
| 487 | QualType RebuildRecordType(RecordDecl *Record) { |
| 488 | return SemaRef.Context.getTypeDeclType(Record); |
| 489 | } |
| 490 | |
| 491 | /// \brief Build a new Enum type. |
| 492 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 493 | return SemaRef.Context.getTypeDeclType(Enum); |
| 494 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 495 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 497 | /// |
| 498 | /// By default, performs semantic analysis when building the typeof type. |
| 499 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 500 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 503 | /// |
| 504 | /// By default, builds a new TypeOfType with the given underlying type. |
| 505 | QualType RebuildTypeOfType(QualType Underlying); |
| 506 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 508 | /// |
| 509 | /// By default, performs semantic analysis when building the decltype type. |
| 510 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 511 | QualType RebuildDecltypeType(ExprArg Underlying); |
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 template specialization type. |
| 514 | /// |
| 515 | /// By default, performs semantic analysis when building the template |
| 516 | /// specialization type. Subclasses may override this routine to provide |
| 517 | /// different behavior. |
| 518 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 519 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 520 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 522 | /// \brief Build a new qualified name type. |
| 523 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 524 | /// By default, builds a new ElaboratedType type from the keyword, |
| 525 | /// the nested-name-specifier and the named type. |
| 526 | /// Subclasses may override this routine to provide different behavior. |
| 527 | QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword, |
| 528 | NestedNameSpecifier *NNS, QualType Named) { |
| 529 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | |
| 532 | /// \brief Build a new typename type that refers to a template-id. |
| 533 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 534 | /// By default, builds a new DependentNameType type from the |
| 535 | /// nested-name-specifier and the given type. Subclasses may override |
| 536 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 537 | QualType RebuildDependentTemplateSpecializationType( |
| 538 | ElaboratedTypeKeyword Keyword, |
| 539 | NestedNameSpecifier *NNS, |
| 540 | const IdentifierInfo *Name, |
| 541 | SourceLocation NameLoc, |
| 542 | const TemplateArgumentListInfo &Args) { |
| 543 | // Rebuild the template name. |
| 544 | // TODO: avoid TemplateName abstraction |
| 545 | TemplateName InstName = |
| 546 | getDerived().RebuildTemplateName(NNS, *Name, QualType()); |
| 547 | |
Douglas Gregor | 7ba0c3f | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 548 | if (InstName.isNull()) |
| 549 | return QualType(); |
| 550 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 551 | // If it's still dependent, make a dependent specialization. |
| 552 | if (InstName.getAsDependentTemplateName()) |
| 553 | return SemaRef.Context.getDependentTemplateSpecializationType( |
| 554 | Keyword, NNS, Name, Args); |
| 555 | |
| 556 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 557 | // specialization. |
| 558 | QualType T = |
| 559 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 560 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 561 | |
Abramo Bagnara | f9985b4 | 2010-08-10 13:46:45 +0000 | [diff] [blame] | 562 | // NOTE: NNS is already recorded in template specialization type T. |
| 563 | return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 565 | |
| 566 | /// \brief Build a new typename type that refers to an identifier. |
| 567 | /// |
| 568 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 569 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 570 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 571 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 572 | NestedNameSpecifier *NNS, |
| 573 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 574 | SourceLocation KeywordLoc, |
| 575 | SourceRange NNSRange, |
| 576 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 577 | CXXScopeSpec SS; |
| 578 | SS.setScopeRep(NNS); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 579 | SS.setRange(NNSRange); |
| 580 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 581 | if (NNS->isDependent()) { |
| 582 | // If the name is still dependent, just build a new dependent name type. |
| 583 | if (!SemaRef.computeDeclContext(SS)) |
| 584 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 585 | } |
| 586 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 587 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 588 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, |
| 589 | KeywordLoc, NNSRange, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 590 | |
| 591 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 592 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 593 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 594 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 595 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 596 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 597 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 598 | if (!DC) |
| 599 | return QualType(); |
| 600 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 601 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 602 | return QualType(); |
| 603 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 604 | TagDecl *Tag = 0; |
| 605 | SemaRef.LookupQualifiedName(Result, DC); |
| 606 | switch (Result.getResultKind()) { |
| 607 | case LookupResult::NotFound: |
| 608 | case LookupResult::NotFoundInCurrentInstantiation: |
| 609 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 611 | case LookupResult::Found: |
| 612 | Tag = Result.getAsSingle<TagDecl>(); |
| 613 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 614 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 615 | case LookupResult::FoundOverloaded: |
| 616 | case LookupResult::FoundUnresolvedValue: |
| 617 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 618 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 619 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 620 | case LookupResult::Ambiguous: |
| 621 | // Let the LookupResult structure handle ambiguities. |
| 622 | return QualType(); |
| 623 | } |
| 624 | |
| 625 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 626 | // FIXME: Would be nice to highlight just the source range. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 627 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 628 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 629 | return QualType(); |
| 630 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 631 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 632 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 633 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 634 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 635 | return QualType(); |
| 636 | } |
| 637 | |
| 638 | // Build the elaborated-type-specifier type. |
| 639 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 640 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 641 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 643 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 644 | /// identifier that names the next step in the nested-name-specifier. |
| 645 | /// |
| 646 | /// By default, performs semantic analysis when building the new |
| 647 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 648 | /// different behavior. |
| 649 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 650 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 651 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 652 | QualType ObjectType, |
| 653 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 654 | |
| 655 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 656 | /// namespace named in the next step in the nested-name-specifier. |
| 657 | /// |
| 658 | /// By default, performs semantic analysis when building the new |
| 659 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 660 | /// different behavior. |
| 661 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 662 | SourceRange Range, |
| 663 | NamespaceDecl *NS); |
| 664 | |
| 665 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 666 | /// type named in the next step in the nested-name-specifier. |
| 667 | /// |
| 668 | /// By default, performs semantic analysis when building the new |
| 669 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 670 | /// different behavior. |
| 671 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 672 | SourceRange Range, |
| 673 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 674 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 675 | |
| 676 | /// \brief Build a new template name given a nested name specifier, a flag |
| 677 | /// indicating whether the "template" keyword was provided, and the template |
| 678 | /// that the template name refers to. |
| 679 | /// |
| 680 | /// By default, builds the new template name directly. Subclasses may override |
| 681 | /// this routine to provide different behavior. |
| 682 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 683 | bool TemplateKW, |
| 684 | TemplateDecl *Template); |
| 685 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 686 | /// \brief Build a new template name given a nested name specifier and the |
| 687 | /// name that is referred to as a template. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis to determine whether the name can |
| 690 | /// be resolved to a specific template, then builds the appropriate kind of |
| 691 | /// template name. Subclasses may override this routine to provide different |
| 692 | /// behavior. |
| 693 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 694 | const IdentifierInfo &II, |
| 695 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 697 | /// \brief Build a new template name given a nested name specifier and the |
| 698 | /// overloaded operator name that is referred to as a template. |
| 699 | /// |
| 700 | /// By default, performs semantic analysis to determine whether the name can |
| 701 | /// be resolved to a specific template, then builds the appropriate kind of |
| 702 | /// template name. Subclasses may override this routine to provide different |
| 703 | /// behavior. |
| 704 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 705 | OverloadedOperatorKind Operator, |
| 706 | QualType ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 707 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 708 | /// \brief Build a new compound statement. |
| 709 | /// |
| 710 | /// By default, performs semantic analysis to build the new statement. |
| 711 | /// Subclasses may override this routine to provide different behavior. |
| 712 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 713 | MultiStmtArg Statements, |
| 714 | SourceLocation RBraceLoc, |
| 715 | bool IsStmtExpr) { |
| 716 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 717 | IsStmtExpr); |
| 718 | } |
| 719 | |
| 720 | /// \brief Build a new case statement. |
| 721 | /// |
| 722 | /// By default, performs semantic analysis to build the new statement. |
| 723 | /// Subclasses may override this routine to provide different behavior. |
| 724 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 725 | ExprArg LHS, |
| 726 | SourceLocation EllipsisLoc, |
| 727 | ExprArg RHS, |
| 728 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 730 | ColonLoc); |
| 731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | /// \brief Attach the body to a new case statement. |
| 734 | /// |
| 735 | /// By default, performs semantic analysis to build the new statement. |
| 736 | /// Subclasses may override this routine to provide different behavior. |
| 737 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 738 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 739 | return move(S); |
| 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 default statement. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis to build the new statement. |
| 745 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 747 | SourceLocation ColonLoc, |
| 748 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 750 | /*CurScope=*/0); |
| 751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 753 | /// \brief Build a new label statement. |
| 754 | /// |
| 755 | /// By default, performs semantic analysis to build the new statement. |
| 756 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | IdentifierInfo *Id, |
| 759 | SourceLocation ColonLoc, |
| 760 | StmtArg SubStmt) { |
| 761 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 762 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 764 | /// \brief Build a new "if" statement. |
| 765 | /// |
| 766 | /// By default, performs semantic analysis to build the new statement. |
| 767 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 768 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 769 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 770 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 771 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 772 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 775 | /// \brief Start building a new switch statement. |
| 776 | /// |
| 777 | /// By default, performs semantic analysis to build the new statement. |
| 778 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 779 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 780 | Sema::ExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 781 | VarDecl *CondVar) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 782 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 783 | DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 784 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 786 | /// \brief Attach the body to the switch statement. |
| 787 | /// |
| 788 | /// By default, performs semantic analysis to build the new statement. |
| 789 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 791 | StmtArg Switch, StmtArg Body) { |
| 792 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 793 | move(Body)); |
| 794 | } |
| 795 | |
| 796 | /// \brief Build a new while statement. |
| 797 | /// |
| 798 | /// By default, performs semantic analysis to build the new statement. |
| 799 | /// Subclasses may override this routine to provide different behavior. |
| 800 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 801 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 802 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 803 | StmtArg Body) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 804 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 805 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 806 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 808 | /// \brief Build a new do-while statement. |
| 809 | /// |
| 810 | /// By default, performs semantic analysis to build the new statement. |
| 811 | /// Subclasses may override this routine to provide different behavior. |
| 812 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 813 | SourceLocation WhileLoc, |
| 814 | SourceLocation LParenLoc, |
| 815 | ExprArg Cond, |
| 816 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 818 | move(Cond), RParenLoc); |
| 819 | } |
| 820 | |
| 821 | /// \brief Build a new for statement. |
| 822 | /// |
| 823 | /// By default, performs semantic analysis to build the new statement. |
| 824 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 826 | SourceLocation LParenLoc, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 827 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 828 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 829 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 830 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 831 | DeclPtrTy::make(CondVar), |
| 832 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 834 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 835 | /// \brief Build a new goto statement. |
| 836 | /// |
| 837 | /// By default, performs semantic analysis to build the new statement. |
| 838 | /// Subclasses may override this routine to provide different behavior. |
| 839 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 840 | SourceLocation LabelLoc, |
| 841 | LabelStmt *Label) { |
| 842 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 843 | } |
| 844 | |
| 845 | /// \brief Build a new indirect goto statement. |
| 846 | /// |
| 847 | /// By default, performs semantic analysis to build the new statement. |
| 848 | /// Subclasses may override this routine to provide different behavior. |
| 849 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 850 | SourceLocation StarLoc, |
| 851 | ExprArg Target) { |
| 852 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 853 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 855 | /// \brief Build a new return statement. |
| 856 | /// |
| 857 | /// By default, performs semantic analysis to build the new statement. |
| 858 | /// Subclasses may override this routine to provide different behavior. |
| 859 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 860 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 861 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 862 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 863 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 864 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 865 | /// \brief Build a new declaration statement. |
| 866 | /// |
| 867 | /// By default, performs semantic analysis to build the new statement. |
| 868 | /// Subclasses may override this routine to provide different behavior. |
| 869 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 871 | SourceLocation EndLoc) { |
| 872 | return getSema().Owned( |
| 873 | new (getSema().Context) DeclStmt( |
| 874 | DeclGroupRef::Create(getSema().Context, |
| 875 | Decls, NumDecls), |
| 876 | StartLoc, EndLoc)); |
| 877 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 878 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 879 | /// \brief Build a new inline asm statement. |
| 880 | /// |
| 881 | /// By default, performs semantic analysis to build the new statement. |
| 882 | /// Subclasses may override this routine to provide different behavior. |
| 883 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 884 | bool IsSimple, |
| 885 | bool IsVolatile, |
| 886 | unsigned NumOutputs, |
| 887 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 888 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 889 | MultiExprArg Constraints, |
| 890 | MultiExprArg Exprs, |
| 891 | ExprArg AsmString, |
| 892 | MultiExprArg Clobbers, |
| 893 | SourceLocation RParenLoc, |
| 894 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 895 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 896 | NumInputs, Names, move(Constraints), |
| 897 | move(Exprs), move(AsmString), move(Clobbers), |
| 898 | RParenLoc, MSAsm); |
| 899 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 900 | |
| 901 | /// \brief Build a new Objective-C @try statement. |
| 902 | /// |
| 903 | /// By default, performs semantic analysis to build the new statement. |
| 904 | /// Subclasses may override this routine to provide different behavior. |
| 905 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 906 | StmtArg TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 907 | MultiStmtArg CatchStmts, |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 908 | StmtArg Finally) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 909 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 910 | move(Finally)); |
| 911 | } |
| 912 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 913 | /// \brief Rebuild an Objective-C exception declaration. |
| 914 | /// |
| 915 | /// By default, performs semantic analysis to build the new declaration. |
| 916 | /// Subclasses may override this routine to provide different behavior. |
| 917 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 918 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 919 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 920 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 921 | ExceptionDecl->getLocation()); |
| 922 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 923 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 924 | /// \brief Build a new Objective-C @catch statement. |
| 925 | /// |
| 926 | /// By default, performs semantic analysis to build the new statement. |
| 927 | /// Subclasses may override this routine to provide different behavior. |
| 928 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 929 | SourceLocation RParenLoc, |
| 930 | VarDecl *Var, |
| 931 | StmtArg Body) { |
| 932 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 933 | Sema::DeclPtrTy::make(Var), |
| 934 | move(Body)); |
| 935 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 937 | /// \brief Build a new Objective-C @finally statement. |
| 938 | /// |
| 939 | /// By default, performs semantic analysis to build the new statement. |
| 940 | /// Subclasses may override this routine to provide different behavior. |
| 941 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 942 | StmtArg Body) { |
| 943 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 944 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 945 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 946 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 947 | /// |
| 948 | /// By default, performs semantic analysis to build the new statement. |
| 949 | /// Subclasses may override this routine to provide different behavior. |
| 950 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 951 | ExprArg Operand) { |
| 952 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 953 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 955 | /// \brief Build a new Objective-C @synchronized statement. |
| 956 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 957 | /// By default, performs semantic analysis to build the new statement. |
| 958 | /// Subclasses may override this routine to provide different behavior. |
| 959 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 960 | ExprArg Object, |
| 961 | StmtArg Body) { |
| 962 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 963 | move(Body)); |
| 964 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 965 | |
| 966 | /// \brief Build a new Objective-C fast enumeration statement. |
| 967 | /// |
| 968 | /// By default, performs semantic analysis to build the new statement. |
| 969 | /// Subclasses may override this routine to provide different behavior. |
| 970 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 971 | SourceLocation LParenLoc, |
| 972 | StmtArg Element, |
| 973 | ExprArg Collection, |
| 974 | SourceLocation RParenLoc, |
| 975 | StmtArg Body) { |
| 976 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 977 | move(Element), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 978 | move(Collection), |
| 979 | RParenLoc, |
| 980 | move(Body)); |
| 981 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 983 | /// \brief Build a new C++ exception declaration. |
| 984 | /// |
| 985 | /// By default, performs semantic analysis to build the new decaration. |
| 986 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 988 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 989 | IdentifierInfo *Name, |
| 990 | SourceLocation Loc, |
| 991 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 993 | TypeRange); |
| 994 | } |
| 995 | |
| 996 | /// \brief Build a new C++ catch statement. |
| 997 | /// |
| 998 | /// By default, performs semantic analysis to build the new statement. |
| 999 | /// Subclasses may override this routine to provide different behavior. |
| 1000 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 1001 | VarDecl *ExceptionDecl, |
| 1002 | StmtArg Handler) { |
| 1003 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1005 | Handler.takeAs<Stmt>())); |
| 1006 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1008 | /// \brief Build a new C++ try statement. |
| 1009 | /// |
| 1010 | /// By default, performs semantic analysis to build the new statement. |
| 1011 | /// Subclasses may override this routine to provide different behavior. |
| 1012 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1013 | StmtArg TryBlock, |
| 1014 | MultiStmtArg Handlers) { |
| 1015 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1018 | /// \brief Build a new expression that references a declaration. |
| 1019 | /// |
| 1020 | /// By default, performs semantic analysis to build the new expression. |
| 1021 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1022 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1023 | LookupResult &R, |
| 1024 | bool RequiresADL) { |
| 1025 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | /// \brief Build a new expression that references a declaration. |
| 1030 | /// |
| 1031 | /// By default, performs semantic analysis to build the new expression. |
| 1032 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1033 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1034 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1035 | ValueDecl *VD, SourceLocation Loc, |
| 1036 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1037 | CXXScopeSpec SS; |
| 1038 | SS.setScopeRep(Qualifier); |
| 1039 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1040 | |
| 1041 | // FIXME: loses template args. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1042 | |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1043 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1044 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1048 | /// By default, performs semantic analysis to build the new expression. |
| 1049 | /// Subclasses may override this routine to provide different behavior. |
| 1050 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1051 | SourceLocation RParen) { |
| 1052 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1053 | } |
| 1054 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1055 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1056 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1057 | /// By default, performs semantic analysis to build the new expression. |
| 1058 | /// Subclasses may override this routine to provide different behavior. |
| 1059 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1060 | SourceLocation OperatorLoc, |
| 1061 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1062 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1063 | SourceRange QualifierRange, |
| 1064 | TypeSourceInfo *ScopeType, |
| 1065 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1066 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1067 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1069 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1071 | /// By default, performs semantic analysis to build the new expression. |
| 1072 | /// Subclasses may override this routine to provide different behavior. |
| 1073 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1074 | UnaryOperator::Opcode Opc, |
| 1075 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1076 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1079 | /// \brief Build a new builtin offsetof expression. |
| 1080 | /// |
| 1081 | /// By default, performs semantic analysis to build the new expression. |
| 1082 | /// Subclasses may override this routine to provide different behavior. |
| 1083 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1084 | TypeSourceInfo *Type, |
| 1085 | Action::OffsetOfComponent *Components, |
| 1086 | unsigned NumComponents, |
| 1087 | SourceLocation RParenLoc) { |
| 1088 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1089 | NumComponents, RParenLoc); |
| 1090 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1091 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1092 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1094 | /// By default, performs semantic analysis to build the new expression. |
| 1095 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1096 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1097 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1099 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1105 | /// By default, performs semantic analysis to build the new expression. |
| 1106 | /// Subclasses may override this routine to provide different behavior. |
| 1107 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1108 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1109 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1110 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1111 | OpLoc, isSizeOf, R); |
| 1112 | if (Result.isInvalid()) |
| 1113 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | SubExpr.release(); |
| 1116 | return move(Result); |
| 1117 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1119 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1121 | /// By default, performs semantic analysis to build the new expression. |
| 1122 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1123 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1124 | SourceLocation LBracketLoc, |
| 1125 | ExprArg RHS, |
| 1126 | SourceLocation RBracketLoc) { |
| 1127 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1129 | RBracketLoc); |
| 1130 | } |
| 1131 | |
| 1132 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1133 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1134 | /// By default, performs semantic analysis to build the new expression. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
| 1136 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1137 | MultiExprArg Args, |
| 1138 | SourceLocation *CommaLocs, |
| 1139 | SourceLocation RParenLoc) { |
| 1140 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1141 | move(Args), CommaLocs, RParenLoc); |
| 1142 | } |
| 1143 | |
| 1144 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1146 | /// By default, performs semantic analysis to build the new expression. |
| 1147 | /// Subclasses may override this routine to provide different behavior. |
| 1148 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1150 | NestedNameSpecifier *Qualifier, |
| 1151 | SourceRange QualifierRange, |
| 1152 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1153 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1154 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1155 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1156 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1157 | if (!Member->getDeclName()) { |
| 1158 | // We have a reference to an unnamed field. |
| 1159 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1160 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1161 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1162 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1163 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1164 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1165 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1167 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1168 | Member, MemberLoc, |
| 1169 | cast<FieldDecl>(Member)->getType()); |
| 1170 | return getSema().Owned(ME); |
| 1171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1173 | CXXScopeSpec SS; |
| 1174 | if (Qualifier) { |
| 1175 | SS.setRange(QualifierRange); |
| 1176 | SS.setScopeRep(Qualifier); |
| 1177 | } |
| 1178 | |
Douglas Gregor | ef4a2a2 | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1179 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 1180 | getSema().DefaultFunctionArrayConversion(BaseExpr); |
| 1181 | QualType BaseType = BaseExpr->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1182 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1183 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1184 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1185 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1186 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1187 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1188 | R.resolveKind(); |
| 1189 | |
Douglas Gregor | ef4a2a2 | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1190 | return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr), |
| 1191 | BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1192 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1193 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1195 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1198 | /// By default, performs semantic analysis to build the new expression. |
| 1199 | /// Subclasses may override this routine to provide different behavior. |
| 1200 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1201 | BinaryOperator::Opcode Opc, |
| 1202 | ExprArg LHS, ExprArg RHS) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1203 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1204 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1208 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1209 | /// By default, performs semantic analysis to build the new expression. |
| 1210 | /// Subclasses may override this routine to provide different behavior. |
| 1211 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1212 | SourceLocation QuestionLoc, |
| 1213 | ExprArg LHS, |
| 1214 | SourceLocation ColonLoc, |
| 1215 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | move(LHS), move(RHS)); |
| 1218 | } |
| 1219 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | /// \brief Build a new C-style cast expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1223 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1224 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1225 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | SourceLocation RParenLoc, |
| 1227 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1228 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1229 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1233 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1234 | /// By default, performs semantic analysis to build the new expression. |
| 1235 | /// Subclasses may override this routine to provide different behavior. |
| 1236 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1237 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | SourceLocation RParenLoc, |
| 1239 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1240 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1241 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1246 | /// By default, performs semantic analysis to build the new expression. |
| 1247 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1248 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1249 | SourceLocation OpLoc, |
| 1250 | SourceLocation AccessorLoc, |
| 1251 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1252 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1253 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1254 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1255 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1256 | OpLoc, /*IsArrow*/ false, |
| 1257 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1258 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1259 | AccessorLoc, |
| 1260 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1265 | /// By default, performs semantic analysis to build the new expression. |
| 1266 | /// Subclasses may override this routine to provide different behavior. |
| 1267 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1268 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1269 | SourceLocation RBraceLoc, |
| 1270 | QualType ResultTy) { |
| 1271 | OwningExprResult Result |
| 1272 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1273 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1274 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1275 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1276 | // Patch in the result type we were given, which may have been computed |
| 1277 | // when the initial InitListExpr was built. |
| 1278 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1279 | ILE->setType(ResultTy); |
| 1280 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1281 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1283 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1285 | /// By default, performs semantic analysis to build the new expression. |
| 1286 | /// Subclasses may override this routine to provide different behavior. |
| 1287 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1288 | MultiExprArg ArrayExprs, |
| 1289 | SourceLocation EqualOrColonLoc, |
| 1290 | bool GNUSyntax, |
| 1291 | ExprArg Init) { |
| 1292 | OwningExprResult Result |
| 1293 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1294 | move(Init)); |
| 1295 | if (Result.isInvalid()) |
| 1296 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1298 | ArrayExprs.release(); |
| 1299 | return move(Result); |
| 1300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1302 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | /// By default, builds the implicit value initialization without performing |
| 1305 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1306 | /// different behavior. |
| 1307 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1308 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | /// By default, performs semantic analysis to build the new expression. |
| 1314 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1315 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| 1316 | ExprArg SubExpr, TypeSourceInfo *TInfo, |
| 1317 | SourceLocation RParenLoc) { |
| 1318 | return getSema().BuildVAArgExpr(BuiltinLoc, |
| 1319 | move(SubExpr), TInfo, |
| 1320 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1324 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1325 | /// By default, performs semantic analysis to build the new expression. |
| 1326 | /// Subclasses may override this routine to provide different behavior. |
| 1327 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1328 | MultiExprArg SubExprs, |
| 1329 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1330 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1331 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | /// |
| 1336 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | /// rather than attempting to map the label statement itself. |
| 1338 | /// Subclasses may override this routine to provide different behavior. |
| 1339 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1340 | SourceLocation LabelLoc, |
| 1341 | LabelStmt *Label) { |
| 1342 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1345 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | /// By default, performs semantic analysis to build the new expression. |
| 1348 | /// Subclasses may override this routine to provide different behavior. |
| 1349 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1350 | StmtArg SubStmt, |
| 1351 | SourceLocation RParenLoc) { |
| 1352 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1353 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1355 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1356 | /// |
| 1357 | /// By default, performs semantic analysis to build the new expression. |
| 1358 | /// Subclasses may override this routine to provide different behavior. |
| 1359 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 1360 | TypeSourceInfo *TInfo1, |
| 1361 | TypeSourceInfo *TInfo2, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1362 | SourceLocation RParenLoc) { |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 1363 | return getSema().BuildTypesCompatibleExpr(BuiltinLoc, |
| 1364 | TInfo1, TInfo2, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | RParenLoc); |
| 1366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | /// \brief Build a new __builtin_choose_expr expression. |
| 1369 | /// |
| 1370 | /// By default, performs semantic analysis to build the new expression. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
| 1372 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1373 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1374 | SourceLocation RParenLoc) { |
| 1375 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1376 | move(Cond), move(LHS), move(RHS), |
| 1377 | RParenLoc); |
| 1378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | /// \brief Build a new overloaded operator call expression. |
| 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new expression. |
| 1383 | /// The semantic analysis provides the behavior of template instantiation, |
| 1384 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1387 | /// provide different behavior. |
| 1388 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1389 | SourceLocation OpLoc, |
| 1390 | ExprArg Callee, |
| 1391 | ExprArg First, |
| 1392 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
| 1394 | /// \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] | 1395 | /// reinterpret_cast. |
| 1396 | /// |
| 1397 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// Subclasses may override this routine to provide different behavior. |
| 1400 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1401 | Stmt::StmtClass Class, |
| 1402 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1403 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | SourceLocation RAngleLoc, |
| 1405 | SourceLocation LParenLoc, |
| 1406 | ExprArg SubExpr, |
| 1407 | SourceLocation RParenLoc) { |
| 1408 | switch (Class) { |
| 1409 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1410 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | move(SubExpr), RParenLoc); |
| 1413 | |
| 1414 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1415 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1419 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1420 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | RAngleLoc, LParenLoc, |
| 1422 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1426 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | default: |
| 1431 | assert(false && "Invalid C++ named cast"); |
| 1432 | break; |
| 1433 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1435 | return getSema().ExprError(); |
| 1436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | /// \brief Build a new C++ static_cast expression. |
| 1439 | /// |
| 1440 | /// By default, performs semantic analysis to build the new expression. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
| 1442 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1443 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1444 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1445 | SourceLocation RAngleLoc, |
| 1446 | SourceLocation LParenLoc, |
| 1447 | ExprArg SubExpr, |
| 1448 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1449 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1450 | TInfo, move(SubExpr), |
| 1451 | SourceRange(LAngleLoc, RAngleLoc), |
| 1452 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | /// \brief Build a new C++ dynamic_cast expression. |
| 1456 | /// |
| 1457 | /// By default, performs semantic analysis to build the new expression. |
| 1458 | /// Subclasses may override this routine to provide different behavior. |
| 1459 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1460 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1461 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | SourceLocation RAngleLoc, |
| 1463 | SourceLocation LParenLoc, |
| 1464 | ExprArg SubExpr, |
| 1465 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1466 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1467 | TInfo, move(SubExpr), |
| 1468 | SourceRange(LAngleLoc, RAngleLoc), |
| 1469 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1473 | /// |
| 1474 | /// By default, performs semantic analysis to build the new expression. |
| 1475 | /// Subclasses may override this routine to provide different behavior. |
| 1476 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1477 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1478 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1479 | SourceLocation RAngleLoc, |
| 1480 | SourceLocation LParenLoc, |
| 1481 | ExprArg SubExpr, |
| 1482 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1483 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1484 | TInfo, move(SubExpr), |
| 1485 | SourceRange(LAngleLoc, RAngleLoc), |
| 1486 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /// \brief Build a new C++ const_cast expression. |
| 1490 | /// |
| 1491 | /// By default, performs semantic analysis to build the new expression. |
| 1492 | /// Subclasses may override this routine to provide different behavior. |
| 1493 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1494 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1495 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | SourceLocation RAngleLoc, |
| 1497 | SourceLocation LParenLoc, |
| 1498 | ExprArg SubExpr, |
| 1499 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1500 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1501 | TInfo, move(SubExpr), |
| 1502 | SourceRange(LAngleLoc, RAngleLoc), |
| 1503 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | /// \brief Build a new C++ functional-style cast expression. |
| 1507 | /// |
| 1508 | /// By default, performs semantic analysis to build the new expression. |
| 1509 | /// Subclasses may override this routine to provide different behavior. |
| 1510 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1511 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | SourceLocation LParenLoc, |
| 1513 | ExprArg SubExpr, |
| 1514 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1515 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1517 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1518 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1519 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1520 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | RParenLoc); |
| 1522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1524 | /// \brief Build a new C++ typeid(type) expression. |
| 1525 | /// |
| 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1528 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1529 | SourceLocation TypeidLoc, |
| 1530 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1532 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1533 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1536 | /// \brief Build a new C++ typeid(expr) expression. |
| 1537 | /// |
| 1538 | /// By default, performs semantic analysis to build the new expression. |
| 1539 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1540 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1541 | SourceLocation TypeidLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1542 | ExprArg Operand, |
| 1543 | SourceLocation RParenLoc) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1544 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1545 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | /// \brief Build a new C++ "this" expression. |
| 1549 | /// |
| 1550 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1551 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1553 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1554 | QualType ThisType, |
| 1555 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1556 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1557 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1558 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | /// \brief Build a new C++ throw expression. |
| 1562 | /// |
| 1563 | /// By default, performs semantic analysis to build the new expression. |
| 1564 | /// Subclasses may override this routine to provide different behavior. |
| 1565 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1566 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1567 | } |
| 1568 | |
| 1569 | /// \brief Build a new C++ default-argument expression. |
| 1570 | /// |
| 1571 | /// By default, builds a new default-argument expression, which does not |
| 1572 | /// require any semantic analysis. Subclasses may override this routine to |
| 1573 | /// provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1574 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1575 | ParmVarDecl *Param) { |
| 1576 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1577 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /// \brief Build a new C++ zero-initialization expression. |
| 1581 | /// |
| 1582 | /// By default, performs semantic analysis to build the new expression. |
| 1583 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 1584 | OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | SourceLocation LParenLoc, |
| 1586 | QualType T, |
| 1587 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1588 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1589 | T.getAsOpaquePtr(), LParenLoc, |
| 1590 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | 0, RParenLoc); |
| 1592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1594 | /// \brief Build a new C++ "new" expression. |
| 1595 | /// |
| 1596 | /// By default, performs semantic analysis to build the new expression. |
| 1597 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1599 | bool UseGlobal, |
| 1600 | SourceLocation PlacementLParen, |
| 1601 | MultiExprArg PlacementArgs, |
| 1602 | SourceLocation PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1603 | SourceRange TypeIdParens, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | QualType AllocType, |
| 1605 | SourceLocation TypeLoc, |
| 1606 | SourceRange TypeRange, |
| 1607 | ExprArg ArraySize, |
| 1608 | SourceLocation ConstructorLParen, |
| 1609 | MultiExprArg ConstructorArgs, |
| 1610 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | PlacementLParen, |
| 1613 | move(PlacementArgs), |
| 1614 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1615 | TypeIdParens, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | AllocType, |
| 1617 | TypeLoc, |
| 1618 | TypeRange, |
| 1619 | move(ArraySize), |
| 1620 | ConstructorLParen, |
| 1621 | move(ConstructorArgs), |
| 1622 | ConstructorRParen); |
| 1623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | /// \brief Build a new C++ "delete" expression. |
| 1626 | /// |
| 1627 | /// By default, performs semantic analysis to build the new expression. |
| 1628 | /// Subclasses may override this routine to provide different behavior. |
| 1629 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1630 | bool IsGlobalDelete, |
| 1631 | bool IsArrayForm, |
| 1632 | ExprArg Operand) { |
| 1633 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1634 | move(Operand)); |
| 1635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1636 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | /// \brief Build a new unary type trait expression. |
| 1638 | /// |
| 1639 | /// By default, performs semantic analysis to build the new expression. |
| 1640 | /// Subclasses may override this routine to provide different behavior. |
| 1641 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1642 | SourceLocation StartLoc, |
| 1643 | SourceLocation LParenLoc, |
| 1644 | QualType T, |
| 1645 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | T.getAsOpaquePtr(), RParenLoc); |
| 1648 | } |
| 1649 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1651 | /// expression. |
| 1652 | /// |
| 1653 | /// By default, performs semantic analysis to build the new expression. |
| 1654 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1655 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1656 | SourceRange QualifierRange, |
| 1657 | DeclarationName Name, |
| 1658 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1659 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | CXXScopeSpec SS; |
| 1661 | SS.setRange(QualifierRange); |
| 1662 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1663 | |
| 1664 | if (TemplateArgs) |
| 1665 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1666 | *TemplateArgs); |
| 1667 | |
| 1668 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /// \brief Build a new template-id expression. |
| 1672 | /// |
| 1673 | /// By default, performs semantic analysis to build the new expression. |
| 1674 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1675 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1676 | LookupResult &R, |
| 1677 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1678 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1679 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | /// \brief Build a new object-construction expression. |
| 1683 | /// |
| 1684 | /// By default, performs semantic analysis to build the new expression. |
| 1685 | /// Subclasses may override this routine to provide different behavior. |
| 1686 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1687 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1688 | CXXConstructorDecl *Constructor, |
| 1689 | bool IsElidable, |
| 1690 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1691 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1692 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1693 | ConvertedArgs)) |
| 1694 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1695 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1696 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1697 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /// \brief Build a new object-construction expression. |
| 1701 | /// |
| 1702 | /// By default, performs semantic analysis to build the new expression. |
| 1703 | /// Subclasses may override this routine to provide different behavior. |
| 1704 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1705 | QualType T, |
| 1706 | SourceLocation LParenLoc, |
| 1707 | MultiExprArg Args, |
| 1708 | SourceLocation *Commas, |
| 1709 | SourceLocation RParenLoc) { |
| 1710 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1711 | T.getAsOpaquePtr(), |
| 1712 | LParenLoc, |
| 1713 | move(Args), |
| 1714 | Commas, |
| 1715 | RParenLoc); |
| 1716 | } |
| 1717 | |
| 1718 | /// \brief Build a new object-construction expression. |
| 1719 | /// |
| 1720 | /// By default, performs semantic analysis to build the new expression. |
| 1721 | /// Subclasses may override this routine to provide different behavior. |
| 1722 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1723 | QualType T, |
| 1724 | SourceLocation LParenLoc, |
| 1725 | MultiExprArg Args, |
| 1726 | SourceLocation *Commas, |
| 1727 | SourceLocation RParenLoc) { |
| 1728 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1729 | /*FIXME*/LParenLoc), |
| 1730 | T.getAsOpaquePtr(), |
| 1731 | LParenLoc, |
| 1732 | move(Args), |
| 1733 | Commas, |
| 1734 | RParenLoc); |
| 1735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1737 | /// \brief Build a new member reference expression. |
| 1738 | /// |
| 1739 | /// By default, performs semantic analysis to build the new expression. |
| 1740 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1741 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1742 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1743 | bool IsArrow, |
| 1744 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1745 | NestedNameSpecifier *Qualifier, |
| 1746 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1747 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1748 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1749 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1750 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1751 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1752 | SS.setRange(QualifierRange); |
| 1753 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1755 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1756 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1757 | SS, FirstQualifierInScope, |
| 1758 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1761 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1762 | /// |
| 1763 | /// By default, performs semantic analysis to build the new expression. |
| 1764 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1765 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1766 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1767 | SourceLocation OperatorLoc, |
| 1768 | bool IsArrow, |
| 1769 | NestedNameSpecifier *Qualifier, |
| 1770 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1771 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1772 | LookupResult &R, |
| 1773 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1774 | CXXScopeSpec SS; |
| 1775 | SS.setRange(QualifierRange); |
| 1776 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1778 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1779 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1780 | SS, FirstQualifierInScope, |
| 1781 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1782 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1784 | /// \brief Build a new Objective-C @encode expression. |
| 1785 | /// |
| 1786 | /// By default, performs semantic analysis to build the new expression. |
| 1787 | /// Subclasses may override this routine to provide different behavior. |
| 1788 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1789 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1790 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1791 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1792 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1795 | /// \brief Build a new Objective-C class message. |
| 1796 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1797 | Selector Sel, |
| 1798 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1799 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1800 | MultiExprArg Args, |
| 1801 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1802 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1803 | ReceiverTypeInfo->getType(), |
| 1804 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1805 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1806 | move(Args)); |
| 1807 | } |
| 1808 | |
| 1809 | /// \brief Build a new Objective-C instance message. |
| 1810 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1811 | Selector Sel, |
| 1812 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1813 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1814 | MultiExprArg Args, |
| 1815 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1816 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1817 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1818 | ReceiverType, |
| 1819 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1820 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1821 | move(Args)); |
| 1822 | } |
| 1823 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1824 | /// \brief Build a new Objective-C ivar reference expression. |
| 1825 | /// |
| 1826 | /// By default, performs semantic analysis to build the new expression. |
| 1827 | /// Subclasses may override this routine to provide different behavior. |
| 1828 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1829 | SourceLocation IvarLoc, |
| 1830 | bool IsArrow, bool IsFreeIvar) { |
| 1831 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1832 | CXXScopeSpec SS; |
| 1833 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1834 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1835 | Sema::LookupMemberName); |
| 1836 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1837 | /*FIME:*/IvarLoc, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1838 | SS, DeclPtrTy(), |
| 1839 | false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1840 | if (Result.isInvalid()) |
| 1841 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1842 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1843 | if (Result.get()) |
| 1844 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1845 | |
| 1846 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1847 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1848 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1849 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1850 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1851 | /*TemplateArgs=*/0); |
| 1852 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1853 | |
| 1854 | /// \brief Build a new Objective-C property reference expression. |
| 1855 | /// |
| 1856 | /// By default, performs semantic analysis to build the new expression. |
| 1857 | /// Subclasses may override this routine to provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1858 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1859 | ObjCPropertyDecl *Property, |
| 1860 | SourceLocation PropertyLoc) { |
| 1861 | CXXScopeSpec SS; |
| 1862 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1863 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1864 | Sema::LookupMemberName); |
| 1865 | bool IsArrow = false; |
| 1866 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1867 | /*FIME:*/PropertyLoc, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1868 | SS, DeclPtrTy(), |
| 1869 | false); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1870 | if (Result.isInvalid()) |
| 1871 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1873 | if (Result.get()) |
| 1874 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1875 | |
| 1876 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1877 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1878 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1879 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1880 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1881 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1882 | /*TemplateArgs=*/0); |
| 1883 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1884 | |
| 1885 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1886 | /// expression. |
| 1887 | /// |
| 1888 | /// By default, performs semantic analysis to build the new expression. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1889 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1890 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1891 | ObjCMethodDecl *Getter, |
| 1892 | QualType T, |
| 1893 | ObjCMethodDecl *Setter, |
| 1894 | SourceLocation NameLoc, |
| 1895 | ExprArg Base) { |
| 1896 | // Since these expressions can only be value-dependent, we do not need to |
| 1897 | // perform semantic analysis again. |
| 1898 | return getSema().Owned( |
| 1899 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1900 | Setter, |
| 1901 | NameLoc, |
| 1902 | Base.takeAs<Expr>())); |
| 1903 | } |
| 1904 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1905 | /// \brief Build a new Objective-C "isa" expression. |
| 1906 | /// |
| 1907 | /// By default, performs semantic analysis to build the new expression. |
| 1908 | /// Subclasses may override this routine to provide different behavior. |
| 1909 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1910 | bool IsArrow) { |
| 1911 | CXXScopeSpec SS; |
| 1912 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1913 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1914 | Sema::LookupMemberName); |
| 1915 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1916 | /*FIME:*/IsaLoc, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1917 | SS, DeclPtrTy(), |
| 1918 | false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1919 | if (Result.isInvalid()) |
| 1920 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1921 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1922 | if (Result.get()) |
| 1923 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1924 | |
| 1925 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1926 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1927 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1928 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1929 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1930 | /*TemplateArgs=*/0); |
| 1931 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1932 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1933 | /// \brief Build a new shuffle vector expression. |
| 1934 | /// |
| 1935 | /// By default, performs semantic analysis to build the new expression. |
| 1936 | /// Subclasses may override this routine to provide different behavior. |
| 1937 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1938 | MultiExprArg SubExprs, |
| 1939 | SourceLocation RParenLoc) { |
| 1940 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1941 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1942 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1943 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1944 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1945 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1947 | // Build a reference to the __builtin_shufflevector builtin |
| 1948 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1950 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1951 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1953 | |
| 1954 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1955 | unsigned NumSubExprs = SubExprs.size(); |
| 1956 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1957 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1958 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 1959 | Builtin->getCallResultType(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1960 | RParenLoc); |
| 1961 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1963 | // Type-check the __builtin_shufflevector expression. |
| 1964 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1965 | if (Result.isInvalid()) |
| 1966 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1967 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1968 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1969 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1970 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1971 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1973 | template<typename Derived> |
| 1974 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1975 | if (!S) |
| 1976 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1978 | switch (S->getStmtClass()) { |
| 1979 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1980 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1981 | // Transform individual statement nodes |
| 1982 | #define STMT(Node, Parent) \ |
| 1983 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1984 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1985 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1986 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1987 | // Transform expressions by calling TransformExpr. |
| 1988 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 1989 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1990 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1991 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1992 | { |
| 1993 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1994 | if (E.isInvalid()) |
| 1995 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1997 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2001 | return SemaRef.Owned(S->Retain()); |
| 2002 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
| 2004 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2005 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2006 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2007 | if (!E) |
| 2008 | return SemaRef.Owned(E); |
| 2009 | |
| 2010 | switch (E->getStmtClass()) { |
| 2011 | case Stmt::NoStmtClass: break; |
| 2012 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2013 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2015 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2016 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2019 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2023 | NestedNameSpecifier * |
| 2024 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2025 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2026 | QualType ObjectType, |
| 2027 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2028 | if (!NNS) |
| 2029 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2030 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2031 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2032 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2033 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2035 | ObjectType, |
| 2036 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2037 | if (!Prefix) |
| 2038 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2039 | |
| 2040 | // 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] | 2041 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2042 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2043 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2044 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2045 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2046 | switch (NNS->getKind()) { |
| 2047 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2049 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2050 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2051 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2052 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2053 | |
| 2054 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2055 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2056 | ObjectType, |
| 2057 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2059 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2060 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2061 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2062 | getDerived().TransformDecl(Range.getBegin(), |
| 2063 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2064 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2065 | Prefix == NNS->getPrefix() && |
| 2066 | NS == NNS->getAsNamespace()) |
| 2067 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2068 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2069 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2071 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2072 | case NestedNameSpecifier::Global: |
| 2073 | // There is no meaningful transformation that one could perform on the |
| 2074 | // global scope. |
| 2075 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2076 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2077 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2078 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2079 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2080 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2081 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2082 | if (T.isNull()) |
| 2083 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2084 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2085 | if (!getDerived().AlwaysRebuild() && |
| 2086 | Prefix == NNS->getPrefix() && |
| 2087 | T == QualType(NNS->getAsType(), 0)) |
| 2088 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2089 | |
| 2090 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2091 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2092 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2093 | } |
| 2094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2095 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2096 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2097 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2101 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2102 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2103 | SourceLocation Loc, |
| 2104 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2105 | if (!Name) |
| 2106 | return Name; |
| 2107 | |
| 2108 | switch (Name.getNameKind()) { |
| 2109 | case DeclarationName::Identifier: |
| 2110 | case DeclarationName::ObjCZeroArgSelector: |
| 2111 | case DeclarationName::ObjCOneArgSelector: |
| 2112 | case DeclarationName::ObjCMultiArgSelector: |
| 2113 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2114 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2115 | case DeclarationName::CXXUsingDirective: |
| 2116 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2117 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2118 | case DeclarationName::CXXConstructorName: |
| 2119 | case DeclarationName::CXXDestructorName: |
| 2120 | case DeclarationName::CXXConversionFunctionName: { |
| 2121 | TemporaryBase Rebase(*this, Loc, Name); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2122 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2123 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2124 | if (T.isNull()) |
| 2125 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2127 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2128 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2129 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2133 | return DeclarationName(); |
| 2134 | } |
| 2135 | |
| 2136 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2137 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2138 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2139 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2140 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2141 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2142 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2143 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2144 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2145 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2146 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2147 | if (!NNS) |
| 2148 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2149 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2150 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2151 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2152 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2153 | if (!TransTemplate) |
| 2154 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2155 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2156 | if (!getDerived().AlwaysRebuild() && |
| 2157 | NNS == QTN->getQualifier() && |
| 2158 | TransTemplate == Template) |
| 2159 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2161 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2162 | TransTemplate); |
| 2163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2164 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2165 | // These should be getting filtered out before they make it into the AST. |
| 2166 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2169 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2171 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2172 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2173 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2174 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2175 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2177 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2178 | NNS == DTN->getQualifier() && |
| 2179 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2180 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2182 | if (DTN->isIdentifier()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2183 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2184 | ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2185 | |
| 2186 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2187 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2189 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2190 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2192 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2193 | if (!TransTemplate) |
| 2194 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2195 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2196 | if (!getDerived().AlwaysRebuild() && |
| 2197 | TransTemplate == Template) |
| 2198 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2200 | return TemplateName(TransTemplate); |
| 2201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2202 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2203 | // These should be getting filtered out before they reach the AST. |
| 2204 | assert(false && "overloaded function decl survived to here"); |
| 2205 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2209 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2210 | const TemplateArgument &Arg, |
| 2211 | TemplateArgumentLoc &Output) { |
| 2212 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2213 | switch (Arg.getKind()) { |
| 2214 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2215 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | |
| 2218 | case TemplateArgument::Type: |
| 2219 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2220 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2221 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2222 | break; |
| 2223 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2224 | case TemplateArgument::Template: |
| 2225 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2226 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2227 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2228 | case TemplateArgument::Expression: |
| 2229 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2230 | break; |
| 2231 | |
| 2232 | case TemplateArgument::Declaration: |
| 2233 | case TemplateArgument::Integral: |
| 2234 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2235 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2236 | break; |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | template<typename Derived> |
| 2241 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2242 | const TemplateArgumentLoc &Input, |
| 2243 | TemplateArgumentLoc &Output) { |
| 2244 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2245 | switch (Arg.getKind()) { |
| 2246 | case TemplateArgument::Null: |
| 2247 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2248 | Output = Input; |
| 2249 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2250 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2251 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2252 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2253 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2254 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2255 | |
| 2256 | DI = getDerived().TransformType(DI); |
| 2257 | if (!DI) return true; |
| 2258 | |
| 2259 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2260 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2262 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2263 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2264 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2265 | DeclarationName Name; |
| 2266 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2267 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2268 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2269 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2270 | if (!D) return true; |
| 2271 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2272 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2273 | if (SourceExpr) { |
| 2274 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2275 | Action::Unevaluated); |
| 2276 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2277 | if (E.isInvalid()) |
| 2278 | SourceExpr = NULL; |
| 2279 | else { |
| 2280 | SourceExpr = E.takeAs<Expr>(); |
| 2281 | SourceExpr->Retain(); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2286 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2288 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2289 | case TemplateArgument::Template: { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2290 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2291 | TemplateName Template |
| 2292 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2293 | if (Template.isNull()) |
| 2294 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2295 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2296 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2297 | Input.getTemplateQualifierRange(), |
| 2298 | Input.getTemplateNameLoc()); |
| 2299 | return false; |
| 2300 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2301 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2302 | case TemplateArgument::Expression: { |
| 2303 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2304 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2305 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2306 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2307 | Expr *InputExpr = Input.getSourceExpression(); |
| 2308 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2309 | |
| 2310 | Sema::OwningExprResult E |
| 2311 | = getDerived().TransformExpr(InputExpr); |
| 2312 | if (E.isInvalid()) return true; |
| 2313 | |
| 2314 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2315 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2316 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2317 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2318 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2319 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2320 | case TemplateArgument::Pack: { |
| 2321 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2322 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2324 | AEnd = Arg.pack_end(); |
| 2325 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2326 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2327 | // FIXME: preserve source information here when we start |
| 2328 | // caring about parameter packs. |
| 2329 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2330 | TemplateArgumentLoc InputArg; |
| 2331 | TemplateArgumentLoc OutputArg; |
| 2332 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2333 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2334 | return true; |
| 2335 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2336 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2337 | } |
| 2338 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2339 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2340 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2341 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2342 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2343 | } |
| 2344 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2345 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2346 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2347 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2348 | } |
| 2349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2350 | //===----------------------------------------------------------------------===// |
| 2351 | // Type transformation |
| 2352 | //===----------------------------------------------------------------------===// |
| 2353 | |
| 2354 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2355 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2356 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2357 | if (getDerived().AlreadyTransformed(T)) |
| 2358 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2359 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2360 | // Temporary workaround. All of these transformations should |
| 2361 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2362 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2363 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2364 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2365 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2366 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2367 | if (!NewDI) |
| 2368 | return QualType(); |
| 2369 | |
| 2370 | return NewDI->getType(); |
| 2371 | } |
| 2372 | |
| 2373 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2374 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2375 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2376 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2377 | return DI; |
| 2378 | |
| 2379 | TypeLocBuilder TLB; |
| 2380 | |
| 2381 | TypeLoc TL = DI->getTypeLoc(); |
| 2382 | TLB.reserve(TL.getFullDataSize()); |
| 2383 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2384 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2385 | if (Result.isNull()) |
| 2386 | return 0; |
| 2387 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2388 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | template<typename Derived> |
| 2392 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2393 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2394 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2395 | switch (T.getTypeLocClass()) { |
| 2396 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2397 | #define TYPELOC(CLASS, PARENT) \ |
| 2398 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2399 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2400 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2401 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2403 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2404 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2405 | return QualType(); |
| 2406 | } |
| 2407 | |
| 2408 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2409 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2410 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2411 | /// types). This is the right thing for template instantiation, but |
| 2412 | /// probably not for other clients. |
| 2413 | template<typename Derived> |
| 2414 | QualType |
| 2415 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2416 | QualifiedTypeLoc T, |
| 2417 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2418 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2419 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2420 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2421 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2422 | if (Result.isNull()) |
| 2423 | return QualType(); |
| 2424 | |
| 2425 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2426 | // FIXME: this is the right thing for template instantiation, but |
| 2427 | // probably not for other clients. |
| 2428 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2429 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2430 | |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 2431 | if (!Quals.empty()) { |
| 2432 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 2433 | TLB.push<QualifiedTypeLoc>(Result); |
| 2434 | // No location information to preserve. |
| 2435 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2436 | |
| 2437 | return Result; |
| 2438 | } |
| 2439 | |
| 2440 | template <class TyLoc> static inline |
| 2441 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2442 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2443 | NewT.setNameLoc(T.getNameLoc()); |
| 2444 | return T.getType(); |
| 2445 | } |
| 2446 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2447 | template<typename Derived> |
| 2448 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2449 | BuiltinTypeLoc T, |
| 2450 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2451 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2452 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2453 | if (T.needsExtraLocalData()) |
| 2454 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2455 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2456 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2457 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2458 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2459 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2460 | ComplexTypeLoc T, |
| 2461 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2462 | // FIXME: recurse? |
| 2463 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2465 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2466 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2467 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2468 | PointerTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2469 | QualType ObjectType) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2470 | QualType PointeeType |
| 2471 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2472 | if (PointeeType.isNull()) |
| 2473 | return QualType(); |
| 2474 | |
| 2475 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2476 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2477 | // A dependent pointer type 'T *' has is being transformed such |
| 2478 | // that an Objective-C class type is being replaced for 'T'. The |
| 2479 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2480 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2481 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2482 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2483 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2484 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2485 | return Result; |
| 2486 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2487 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2488 | if (getDerived().AlwaysRebuild() || |
| 2489 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2490 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2491 | if (Result.isNull()) |
| 2492 | return QualType(); |
| 2493 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2494 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2495 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2496 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2497 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2499 | |
| 2500 | template<typename Derived> |
| 2501 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2502 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2503 | BlockPointerTypeLoc TL, |
| 2504 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2505 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2506 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2507 | if (PointeeType.isNull()) |
| 2508 | return QualType(); |
| 2509 | |
| 2510 | QualType Result = TL.getType(); |
| 2511 | if (getDerived().AlwaysRebuild() || |
| 2512 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2513 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2514 | TL.getSigilLoc()); |
| 2515 | if (Result.isNull()) |
| 2516 | return QualType(); |
| 2517 | } |
| 2518 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2519 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2520 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2521 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2524 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2525 | /// don't care whether the type itself is an l-value type or an r-value |
| 2526 | /// type; we only care if the type was *written* as an l-value type |
| 2527 | /// or an r-value type. |
| 2528 | template<typename Derived> |
| 2529 | QualType |
| 2530 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2531 | ReferenceTypeLoc TL, |
| 2532 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2533 | const ReferenceType *T = TL.getTypePtr(); |
| 2534 | |
| 2535 | // Note that this works with the pointee-as-written. |
| 2536 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2537 | if (PointeeType.isNull()) |
| 2538 | return QualType(); |
| 2539 | |
| 2540 | QualType Result = TL.getType(); |
| 2541 | if (getDerived().AlwaysRebuild() || |
| 2542 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2543 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2544 | T->isSpelledAsLValue(), |
| 2545 | TL.getSigilLoc()); |
| 2546 | if (Result.isNull()) |
| 2547 | return QualType(); |
| 2548 | } |
| 2549 | |
| 2550 | // r-value references can be rebuilt as l-value references. |
| 2551 | ReferenceTypeLoc NewTL; |
| 2552 | if (isa<LValueReferenceType>(Result)) |
| 2553 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2554 | else |
| 2555 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2556 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2557 | |
| 2558 | return Result; |
| 2559 | } |
| 2560 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | template<typename Derived> |
| 2562 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2563 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2564 | LValueReferenceTypeLoc TL, |
| 2565 | QualType ObjectType) { |
| 2566 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2569 | template<typename Derived> |
| 2570 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2571 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2572 | RValueReferenceTypeLoc TL, |
| 2573 | QualType ObjectType) { |
| 2574 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2576 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2577 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2579 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2580 | MemberPointerTypeLoc TL, |
| 2581 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2582 | MemberPointerType *T = TL.getTypePtr(); |
| 2583 | |
| 2584 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2585 | if (PointeeType.isNull()) |
| 2586 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2588 | // TODO: preserve source information for this. |
| 2589 | QualType ClassType |
| 2590 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2591 | if (ClassType.isNull()) |
| 2592 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2593 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2594 | QualType Result = TL.getType(); |
| 2595 | if (getDerived().AlwaysRebuild() || |
| 2596 | PointeeType != T->getPointeeType() || |
| 2597 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2598 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2599 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2600 | if (Result.isNull()) |
| 2601 | return QualType(); |
| 2602 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2603 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2604 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2605 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2606 | |
| 2607 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | template<typename Derived> |
| 2611 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2612 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2613 | ConstantArrayTypeLoc TL, |
| 2614 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2615 | ConstantArrayType *T = TL.getTypePtr(); |
| 2616 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2617 | if (ElementType.isNull()) |
| 2618 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2620 | QualType Result = TL.getType(); |
| 2621 | if (getDerived().AlwaysRebuild() || |
| 2622 | ElementType != T->getElementType()) { |
| 2623 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2624 | T->getSizeModifier(), |
| 2625 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2626 | T->getIndexTypeCVRQualifiers(), |
| 2627 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2628 | if (Result.isNull()) |
| 2629 | return QualType(); |
| 2630 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2631 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2632 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2633 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2634 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2635 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2636 | Expr *Size = TL.getSizeExpr(); |
| 2637 | if (Size) { |
| 2638 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2639 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2640 | } |
| 2641 | NewTL.setSizeExpr(Size); |
| 2642 | |
| 2643 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2645 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2646 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2647 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2648 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2649 | IncompleteArrayTypeLoc TL, |
| 2650 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2651 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2652 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2653 | if (ElementType.isNull()) |
| 2654 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2655 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2656 | QualType Result = TL.getType(); |
| 2657 | if (getDerived().AlwaysRebuild() || |
| 2658 | ElementType != T->getElementType()) { |
| 2659 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2660 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2661 | T->getIndexTypeCVRQualifiers(), |
| 2662 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2663 | if (Result.isNull()) |
| 2664 | return QualType(); |
| 2665 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2666 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2667 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2668 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2669 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2670 | NewTL.setSizeExpr(0); |
| 2671 | |
| 2672 | return Result; |
| 2673 | } |
| 2674 | |
| 2675 | template<typename Derived> |
| 2676 | QualType |
| 2677 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2678 | VariableArrayTypeLoc TL, |
| 2679 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2680 | VariableArrayType *T = TL.getTypePtr(); |
| 2681 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2682 | if (ElementType.isNull()) |
| 2683 | return QualType(); |
| 2684 | |
| 2685 | // Array bounds are not potentially evaluated contexts |
| 2686 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2687 | |
| 2688 | Sema::OwningExprResult SizeResult |
| 2689 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2690 | if (SizeResult.isInvalid()) |
| 2691 | return QualType(); |
| 2692 | |
| 2693 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2694 | |
| 2695 | QualType Result = TL.getType(); |
| 2696 | if (getDerived().AlwaysRebuild() || |
| 2697 | ElementType != T->getElementType() || |
| 2698 | Size != T->getSizeExpr()) { |
| 2699 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2700 | T->getSizeModifier(), |
| 2701 | move(SizeResult), |
| 2702 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2703 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2704 | if (Result.isNull()) |
| 2705 | return QualType(); |
| 2706 | } |
| 2707 | else SizeResult.take(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2708 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2709 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2710 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2711 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2712 | NewTL.setSizeExpr(Size); |
| 2713 | |
| 2714 | return Result; |
| 2715 | } |
| 2716 | |
| 2717 | template<typename Derived> |
| 2718 | QualType |
| 2719 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2720 | DependentSizedArrayTypeLoc TL, |
| 2721 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2722 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2723 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2724 | if (ElementType.isNull()) |
| 2725 | return QualType(); |
| 2726 | |
| 2727 | // Array bounds are not potentially evaluated contexts |
| 2728 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2729 | |
| 2730 | Sema::OwningExprResult SizeResult |
| 2731 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2732 | if (SizeResult.isInvalid()) |
| 2733 | return QualType(); |
| 2734 | |
| 2735 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2736 | |
| 2737 | QualType Result = TL.getType(); |
| 2738 | if (getDerived().AlwaysRebuild() || |
| 2739 | ElementType != T->getElementType() || |
| 2740 | Size != T->getSizeExpr()) { |
| 2741 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2742 | T->getSizeModifier(), |
| 2743 | move(SizeResult), |
| 2744 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2745 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2746 | if (Result.isNull()) |
| 2747 | return QualType(); |
| 2748 | } |
| 2749 | else SizeResult.take(); |
| 2750 | |
| 2751 | // We might have any sort of array type now, but fortunately they |
| 2752 | // all have the same location layout. |
| 2753 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2754 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2755 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2756 | NewTL.setSizeExpr(Size); |
| 2757 | |
| 2758 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2759 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2760 | |
| 2761 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2762 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2763 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2764 | DependentSizedExtVectorTypeLoc TL, |
| 2765 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2766 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2767 | |
| 2768 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2769 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2770 | if (ElementType.isNull()) |
| 2771 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2772 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2773 | // Vector sizes are not potentially evaluated contexts |
| 2774 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2775 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2776 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2777 | if (Size.isInvalid()) |
| 2778 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2779 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | QualType Result = TL.getType(); |
| 2781 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2782 | ElementType != T->getElementType() || |
| 2783 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2784 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2785 | move(Size), |
| 2786 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2787 | if (Result.isNull()) |
| 2788 | return QualType(); |
| 2789 | } |
| 2790 | else Size.take(); |
| 2791 | |
| 2792 | // Result might be dependent or not. |
| 2793 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2794 | DependentSizedExtVectorTypeLoc NewTL |
| 2795 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2796 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2797 | } else { |
| 2798 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2799 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2800 | } |
| 2801 | |
| 2802 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | |
| 2805 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2806 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2807 | VectorTypeLoc TL, |
| 2808 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2809 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2810 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2811 | if (ElementType.isNull()) |
| 2812 | return QualType(); |
| 2813 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2814 | QualType Result = TL.getType(); |
| 2815 | if (getDerived().AlwaysRebuild() || |
| 2816 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2817 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2818 | T->getAltiVecSpecific()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2819 | if (Result.isNull()) |
| 2820 | return QualType(); |
| 2821 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2822 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2823 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2824 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2825 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2826 | return Result; |
| 2827 | } |
| 2828 | |
| 2829 | template<typename Derived> |
| 2830 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2831 | ExtVectorTypeLoc TL, |
| 2832 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2833 | VectorType *T = TL.getTypePtr(); |
| 2834 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2835 | if (ElementType.isNull()) |
| 2836 | return QualType(); |
| 2837 | |
| 2838 | QualType Result = TL.getType(); |
| 2839 | if (getDerived().AlwaysRebuild() || |
| 2840 | ElementType != T->getElementType()) { |
| 2841 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2842 | T->getNumElements(), |
| 2843 | /*FIXME*/ SourceLocation()); |
| 2844 | if (Result.isNull()) |
| 2845 | return QualType(); |
| 2846 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2847 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2848 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2849 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2850 | |
| 2851 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2852 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2853 | |
| 2854 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2855 | ParmVarDecl * |
| 2856 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2857 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2858 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2859 | if (!NewDI) |
| 2860 | return 0; |
| 2861 | |
| 2862 | if (NewDI == OldDI) |
| 2863 | return OldParm; |
| 2864 | else |
| 2865 | return ParmVarDecl::Create(SemaRef.Context, |
| 2866 | OldParm->getDeclContext(), |
| 2867 | OldParm->getLocation(), |
| 2868 | OldParm->getIdentifier(), |
| 2869 | NewDI->getType(), |
| 2870 | NewDI, |
| 2871 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2872 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2873 | /* DefArg */ NULL); |
| 2874 | } |
| 2875 | |
| 2876 | template<typename Derived> |
| 2877 | bool TreeTransform<Derived>:: |
| 2878 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2879 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2880 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2881 | FunctionProtoType *T = TL.getTypePtr(); |
| 2882 | |
| 2883 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2884 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2885 | |
| 2886 | QualType NewType; |
| 2887 | ParmVarDecl *NewParm; |
| 2888 | |
| 2889 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2890 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2891 | if (!NewParm) |
| 2892 | return true; |
| 2893 | NewType = NewParm->getType(); |
| 2894 | |
| 2895 | // Deal with the possibility that we don't have a parameter |
| 2896 | // declaration for this parameter. |
| 2897 | } else { |
| 2898 | NewParm = 0; |
| 2899 | |
| 2900 | QualType OldType = T->getArgType(i); |
| 2901 | NewType = getDerived().TransformType(OldType); |
| 2902 | if (NewType.isNull()) |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
| 2906 | PTypes.push_back(NewType); |
| 2907 | PVars.push_back(NewParm); |
| 2908 | } |
| 2909 | |
| 2910 | return false; |
| 2911 | } |
| 2912 | |
| 2913 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2914 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2915 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2916 | FunctionProtoTypeLoc TL, |
| 2917 | QualType ObjectType) { |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2918 | // Transform the parameters. We do this first for the benefit of template |
| 2919 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2920 | // instantiation scope before we transform the function type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2921 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2922 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2923 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2924 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2925 | |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2926 | FunctionProtoType *T = TL.getTypePtr(); |
| 2927 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2928 | if (ResultType.isNull()) |
| 2929 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2930 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2931 | QualType Result = TL.getType(); |
| 2932 | if (getDerived().AlwaysRebuild() || |
| 2933 | ResultType != T->getResultType() || |
| 2934 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2935 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2936 | ParamTypes.data(), |
| 2937 | ParamTypes.size(), |
| 2938 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 2939 | T->getTypeQuals(), |
| 2940 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2941 | if (Result.isNull()) |
| 2942 | return QualType(); |
| 2943 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2944 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2945 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2946 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2947 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2948 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2949 | NewTL.setArg(i, ParamDecls[i]); |
| 2950 | |
| 2951 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2954 | template<typename Derived> |
| 2955 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2956 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2957 | FunctionNoProtoTypeLoc TL, |
| 2958 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2959 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2960 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2961 | if (ResultType.isNull()) |
| 2962 | return QualType(); |
| 2963 | |
| 2964 | QualType Result = TL.getType(); |
| 2965 | if (getDerived().AlwaysRebuild() || |
| 2966 | ResultType != T->getResultType()) |
| 2967 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2968 | |
| 2969 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2970 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2971 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2972 | |
| 2973 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2974 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2975 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2976 | template<typename Derived> QualType |
| 2977 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2978 | UnresolvedUsingTypeLoc TL, |
| 2979 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2980 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2981 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2982 | if (!D) |
| 2983 | return QualType(); |
| 2984 | |
| 2985 | QualType Result = TL.getType(); |
| 2986 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2987 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2988 | if (Result.isNull()) |
| 2989 | return QualType(); |
| 2990 | } |
| 2991 | |
| 2992 | // We might get an arbitrary type spec type back. We should at |
| 2993 | // least always get a type spec type, though. |
| 2994 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2995 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2996 | |
| 2997 | return Result; |
| 2998 | } |
| 2999 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3000 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3001 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3002 | TypedefTypeLoc TL, |
| 3003 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3004 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3005 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3006 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3007 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3008 | if (!Typedef) |
| 3009 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3010 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3011 | QualType Result = TL.getType(); |
| 3012 | if (getDerived().AlwaysRebuild() || |
| 3013 | Typedef != T->getDecl()) { |
| 3014 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3015 | if (Result.isNull()) |
| 3016 | return QualType(); |
| 3017 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3019 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3020 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3021 | |
| 3022 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3025 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3026 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3027 | TypeOfExprTypeLoc TL, |
| 3028 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3029 | // typeof expressions are not potentially evaluated contexts |
| 3030 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3032 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3033 | if (E.isInvalid()) |
| 3034 | return QualType(); |
| 3035 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3036 | QualType Result = TL.getType(); |
| 3037 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3038 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3039 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3040 | if (Result.isNull()) |
| 3041 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3042 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3043 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3045 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3046 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3047 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3048 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3049 | |
| 3050 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3051 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 | |
| 3053 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3054 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3055 | TypeOfTypeLoc TL, |
| 3056 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3057 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3058 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3059 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3060 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3063 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3064 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3065 | if (Result.isNull()) |
| 3066 | return QualType(); |
| 3067 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3068 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3069 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3070 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3071 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3072 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3073 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3074 | |
| 3075 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | |
| 3078 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3079 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3080 | DecltypeTypeLoc TL, |
| 3081 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3082 | DecltypeType *T = TL.getTypePtr(); |
| 3083 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3084 | // decltype expressions are not potentially evaluated contexts |
| 3085 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3086 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3087 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3088 | if (E.isInvalid()) |
| 3089 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3090 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3091 | QualType Result = TL.getType(); |
| 3092 | if (getDerived().AlwaysRebuild() || |
| 3093 | E.get() != T->getUnderlyingExpr()) { |
| 3094 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3095 | if (Result.isNull()) |
| 3096 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3097 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3098 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3099 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3100 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3101 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3102 | |
| 3103 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3107 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3108 | RecordTypeLoc TL, |
| 3109 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3110 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3111 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3112 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3113 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3114 | if (!Record) |
| 3115 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3116 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3117 | QualType Result = TL.getType(); |
| 3118 | if (getDerived().AlwaysRebuild() || |
| 3119 | Record != T->getDecl()) { |
| 3120 | Result = getDerived().RebuildRecordType(Record); |
| 3121 | if (Result.isNull()) |
| 3122 | return QualType(); |
| 3123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3125 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3126 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3127 | |
| 3128 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3129 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3130 | |
| 3131 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3132 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3133 | EnumTypeLoc TL, |
| 3134 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3135 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3136 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3137 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3138 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3139 | if (!Enum) |
| 3140 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3141 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3142 | QualType Result = TL.getType(); |
| 3143 | if (getDerived().AlwaysRebuild() || |
| 3144 | Enum != T->getDecl()) { |
| 3145 | Result = getDerived().RebuildEnumType(Enum); |
| 3146 | if (Result.isNull()) |
| 3147 | return QualType(); |
| 3148 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3150 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3151 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3152 | |
| 3153 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3154 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3155 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3156 | template<typename Derived> |
| 3157 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3158 | TypeLocBuilder &TLB, |
| 3159 | InjectedClassNameTypeLoc TL, |
| 3160 | QualType ObjectType) { |
| 3161 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3162 | TL.getTypePtr()->getDecl()); |
| 3163 | if (!D) return QualType(); |
| 3164 | |
| 3165 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3166 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3167 | return T; |
| 3168 | } |
| 3169 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3170 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3171 | template<typename Derived> |
| 3172 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3173 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3174 | TemplateTypeParmTypeLoc TL, |
| 3175 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3176 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3179 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3180 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3181 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3182 | SubstTemplateTypeParmTypeLoc TL, |
| 3183 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3184 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3188 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3189 | const TemplateSpecializationType *TST, |
| 3190 | QualType ObjectType) { |
| 3191 | // FIXME: this entire method is a temporary workaround; callers |
| 3192 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3193 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3194 | // Fake up a TemplateSpecializationTypeLoc. |
| 3195 | TypeLocBuilder TLB; |
| 3196 | TemplateSpecializationTypeLoc TL |
| 3197 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3198 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3199 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3200 | |
| 3201 | TL.setTemplateNameLoc(BaseLoc); |
| 3202 | TL.setLAngleLoc(BaseLoc); |
| 3203 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3204 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3205 | const TemplateArgument &TA = TST->getArg(i); |
| 3206 | TemplateArgumentLoc TAL; |
| 3207 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3208 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3209 | } |
| 3210 | |
| 3211 | TypeLocBuilder IgnoredTLB; |
| 3212 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3213 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3214 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3215 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3216 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3217 | TypeLocBuilder &TLB, |
| 3218 | TemplateSpecializationTypeLoc TL, |
| 3219 | QualType ObjectType) { |
| 3220 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3221 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3222 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3223 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3224 | if (Template.isNull()) |
| 3225 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3226 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3227 | TemplateArgumentListInfo NewTemplateArgs; |
| 3228 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3229 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3230 | |
| 3231 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3232 | TemplateArgumentLoc Loc; |
| 3233 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3234 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3235 | NewTemplateArgs.addArgument(Loc); |
| 3236 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3237 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3238 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3239 | |
| 3240 | QualType Result = |
| 3241 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3242 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3243 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3244 | |
| 3245 | if (!Result.isNull()) { |
| 3246 | TemplateSpecializationTypeLoc NewTL |
| 3247 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3248 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3249 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3250 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3251 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3252 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3255 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3256 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | |
| 3258 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3259 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3260 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 3261 | ElaboratedTypeLoc TL, |
| 3262 | QualType ObjectType) { |
| 3263 | ElaboratedType *T = TL.getTypePtr(); |
| 3264 | |
| 3265 | NestedNameSpecifier *NNS = 0; |
| 3266 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 3267 | if (T->getQualifier() != 0) { |
| 3268 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3269 | TL.getQualifierRange(), |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3270 | ObjectType); |
| 3271 | if (!NNS) |
| 3272 | return QualType(); |
| 3273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3274 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3275 | QualType NamedT; |
| 3276 | // FIXME: this test is meant to workaround a problem (failing assertion) |
| 3277 | // occurring if directly executing the code in the else branch. |
| 3278 | if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) { |
| 3279 | TemplateSpecializationTypeLoc OldNamedTL |
| 3280 | = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc()); |
| 3281 | const TemplateSpecializationType* OldTST |
Jim Grosbach | db06151 | 2010-05-19 23:53:08 +0000 | [diff] [blame] | 3282 | = OldNamedTL.getType()->template getAs<TemplateSpecializationType>(); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3283 | NamedT = TransformTemplateSpecializationType(OldTST, ObjectType); |
| 3284 | if (NamedT.isNull()) |
| 3285 | return QualType(); |
| 3286 | TemplateSpecializationTypeLoc NewNamedTL |
| 3287 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3288 | NewNamedTL.copy(OldNamedTL); |
| 3289 | } |
| 3290 | else { |
| 3291 | NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 3292 | if (NamedT.isNull()) |
| 3293 | return QualType(); |
| 3294 | } |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 3295 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3296 | QualType Result = TL.getType(); |
| 3297 | if (getDerived().AlwaysRebuild() || |
| 3298 | NNS != T->getQualifier() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3299 | NamedT != T->getNamedType()) { |
| 3300 | Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3301 | if (Result.isNull()) |
| 3302 | return QualType(); |
| 3303 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3304 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3305 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3306 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3307 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3308 | |
| 3309 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3311 | |
| 3312 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3313 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3314 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3315 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3316 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3317 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3318 | NestedNameSpecifier *NNS |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3319 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3320 | TL.getQualifierRange(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3321 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3322 | if (!NNS) |
| 3323 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3325 | QualType Result |
| 3326 | = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3327 | T->getIdentifier(), |
| 3328 | TL.getKeywordLoc(), |
| 3329 | TL.getQualifierRange(), |
| 3330 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3331 | if (Result.isNull()) |
| 3332 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3333 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3334 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 3335 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3336 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 3337 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3338 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3339 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3340 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3341 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3342 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 3343 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3344 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3345 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3346 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3347 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3350 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3351 | QualType TreeTransform<Derived>:: |
| 3352 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 3353 | DependentTemplateSpecializationTypeLoc TL, |
| 3354 | QualType ObjectType) { |
| 3355 | DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 3356 | |
| 3357 | NestedNameSpecifier *NNS |
| 3358 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3359 | TL.getQualifierRange(), |
| 3360 | ObjectType); |
| 3361 | if (!NNS) |
| 3362 | return QualType(); |
| 3363 | |
| 3364 | TemplateArgumentListInfo NewTemplateArgs; |
| 3365 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3366 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3367 | |
| 3368 | for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) { |
| 3369 | TemplateArgumentLoc Loc; |
| 3370 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc)) |
| 3371 | return QualType(); |
| 3372 | NewTemplateArgs.addArgument(Loc); |
| 3373 | } |
| 3374 | |
| 3375 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| 3376 | T->getKeyword(), |
| 3377 | NNS, |
| 3378 | T->getIdentifier(), |
| 3379 | TL.getNameLoc(), |
| 3380 | NewTemplateArgs); |
| 3381 | if (Result.isNull()) |
| 3382 | return QualType(); |
| 3383 | |
| 3384 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 3385 | QualType NamedT = ElabT->getNamedType(); |
| 3386 | |
| 3387 | // Copy information relevant to the template specialization. |
| 3388 | TemplateSpecializationTypeLoc NamedTL |
| 3389 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3390 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3391 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3392 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3393 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 3394 | |
| 3395 | // Copy information relevant to the elaborated type. |
| 3396 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3397 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3398 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3399 | } else { |
Douglas Gregor | ffa2039 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 3400 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 3401 | TLB.pushFullCopy(NewTL); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3402 | } |
| 3403 | return Result; |
| 3404 | } |
| 3405 | |
| 3406 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3407 | QualType |
| 3408 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3409 | ObjCInterfaceTypeLoc TL, |
| 3410 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3411 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3412 | TLB.pushFullCopy(TL); |
| 3413 | return TL.getType(); |
| 3414 | } |
| 3415 | |
| 3416 | template<typename Derived> |
| 3417 | QualType |
| 3418 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 3419 | ObjCObjectTypeLoc TL, |
| 3420 | QualType ObjectType) { |
| 3421 | // ObjCObjectType is never dependent. |
| 3422 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3423 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | |
| 3426 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3427 | QualType |
| 3428 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3429 | ObjCObjectPointerTypeLoc TL, |
| 3430 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3431 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3432 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3433 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3434 | } |
| 3435 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3436 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3437 | // Statement transformation |
| 3438 | //===----------------------------------------------------------------------===// |
| 3439 | template<typename Derived> |
| 3440 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3442 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | template<typename Derived> |
| 3446 | Sema::OwningStmtResult |
| 3447 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3448 | return getDerived().TransformCompoundStmt(S, false); |
| 3449 | } |
| 3450 | |
| 3451 | template<typename Derived> |
| 3452 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3453 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3454 | bool IsStmtExpr) { |
| 3455 | bool SubStmtChanged = false; |
| 3456 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3457 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3458 | B != BEnd; ++B) { |
| 3459 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3460 | if (Result.isInvalid()) |
| 3461 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3463 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3464 | Statements.push_back(Result.takeAs<Stmt>()); |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 3468 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3470 | |
| 3471 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3472 | move_arg(Statements), |
| 3473 | S->getRBracLoc(), |
| 3474 | IsStmtExpr); |
| 3475 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3476 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3477 | template<typename Derived> |
| 3478 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3480 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3481 | { |
| 3482 | // The case value expressions are not potentially evaluated. |
| 3483 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3484 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3485 | // Transform the left-hand case value. |
| 3486 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3487 | if (LHS.isInvalid()) |
| 3488 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3490 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3491 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3492 | if (RHS.isInvalid()) |
| 3493 | return SemaRef.StmtError(); |
| 3494 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3495 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3496 | // Build the case statement. |
| 3497 | // Case statements are always rebuilt so that they will attached to their |
| 3498 | // transformed switch statement. |
| 3499 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3500 | move(LHS), |
| 3501 | S->getEllipsisLoc(), |
| 3502 | move(RHS), |
| 3503 | S->getColonLoc()); |
| 3504 | if (Case.isInvalid()) |
| 3505 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3506 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3507 | // Transform the statement following the case |
| 3508 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3509 | if (SubStmt.isInvalid()) |
| 3510 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3511 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3512 | // Attach the body to the case statement |
| 3513 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3514 | } |
| 3515 | |
| 3516 | template<typename Derived> |
| 3517 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3519 | // Transform the statement following the default case |
| 3520 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3521 | if (SubStmt.isInvalid()) |
| 3522 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3524 | // Default statements are always rebuilt |
| 3525 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3526 | move(SubStmt)); |
| 3527 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3529 | template<typename Derived> |
| 3530 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3532 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3533 | if (SubStmt.isInvalid()) |
| 3534 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3536 | // FIXME: Pass the real colon location in. |
| 3537 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3538 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3539 | move(SubStmt)); |
| 3540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | Sema::OwningStmtResult |
| 3544 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3546 | OwningExprResult Cond(SemaRef); |
| 3547 | VarDecl *ConditionVar = 0; |
| 3548 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3549 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3550 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3551 | getDerived().TransformDefinition( |
| 3552 | S->getConditionVariable()->getLocation(), |
| 3553 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3554 | if (!ConditionVar) |
| 3555 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3556 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3557 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3559 | if (Cond.isInvalid()) |
| 3560 | return SemaRef.StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3561 | |
| 3562 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3563 | if (S->getCond()) { |
| 3564 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3565 | S->getIfLoc(), |
| 3566 | move(Cond)); |
| 3567 | if (CondE.isInvalid()) |
| 3568 | return getSema().StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3570 | Cond = move(CondE); |
| 3571 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3572 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3573 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3574 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3575 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3576 | return SemaRef.StmtError(); |
| 3577 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3578 | // Transform the "then" branch. |
| 3579 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3580 | if (Then.isInvalid()) |
| 3581 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3583 | // Transform the "else" branch. |
| 3584 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3585 | if (Else.isInvalid()) |
| 3586 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3587 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3588 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3589 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3590 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3591 | Then.get() == S->getThen() && |
| 3592 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3593 | return SemaRef.Owned(S->Retain()); |
| 3594 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3595 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3596 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3597 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | template<typename Derived> |
| 3601 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3602 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3603 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3604 | OwningExprResult Cond(SemaRef); |
| 3605 | VarDecl *ConditionVar = 0; |
| 3606 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3607 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3608 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3609 | getDerived().TransformDefinition( |
| 3610 | S->getConditionVariable()->getLocation(), |
| 3611 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3612 | if (!ConditionVar) |
| 3613 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3614 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3615 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3616 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3617 | if (Cond.isInvalid()) |
| 3618 | return SemaRef.StmtError(); |
| 3619 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3621 | // Rebuild the switch statement. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3622 | OwningStmtResult Switch |
| 3623 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3624 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3625 | if (Switch.isInvalid()) |
| 3626 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3628 | // Transform the body of the switch statement. |
| 3629 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3630 | if (Body.isInvalid()) |
| 3631 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3633 | // Complete the switch statement. |
| 3634 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3635 | move(Body)); |
| 3636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3638 | template<typename Derived> |
| 3639 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3641 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3642 | OwningExprResult Cond(SemaRef); |
| 3643 | VarDecl *ConditionVar = 0; |
| 3644 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3645 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3646 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3647 | getDerived().TransformDefinition( |
| 3648 | S->getConditionVariable()->getLocation(), |
| 3649 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3650 | if (!ConditionVar) |
| 3651 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3652 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3653 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3654 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3655 | if (Cond.isInvalid()) |
| 3656 | return SemaRef.StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3657 | |
| 3658 | if (S->getCond()) { |
| 3659 | // Convert the condition to a boolean value. |
| 3660 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3661 | S->getWhileLoc(), |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3662 | move(Cond)); |
| 3663 | if (CondE.isInvalid()) |
| 3664 | return getSema().StmtError(); |
| 3665 | Cond = move(CondE); |
| 3666 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3668 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3669 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3670 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3671 | return SemaRef.StmtError(); |
| 3672 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3673 | // Transform the body |
| 3674 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3675 | if (Body.isInvalid()) |
| 3676 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3678 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3679 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3680 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3681 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | return SemaRef.Owned(S->Retain()); |
| 3683 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3684 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3685 | ConditionVar, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3686 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3687 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3688 | template<typename Derived> |
| 3689 | Sema::OwningStmtResult |
| 3690 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3691 | // Transform the body |
| 3692 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3693 | if (Body.isInvalid()) |
| 3694 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3695 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3696 | // Transform the condition |
| 3697 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3698 | if (Cond.isInvalid()) |
| 3699 | return SemaRef.StmtError(); |
| 3700 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3701 | if (!getDerived().AlwaysRebuild() && |
| 3702 | Cond.get() == S->getCond() && |
| 3703 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3704 | return SemaRef.Owned(S->Retain()); |
| 3705 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3706 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3707 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3708 | S->getRParenLoc()); |
| 3709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3710 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3711 | template<typename Derived> |
| 3712 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3714 | // Transform the initialization statement |
| 3715 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3716 | if (Init.isInvalid()) |
| 3717 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3719 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3720 | OwningExprResult Cond(SemaRef); |
| 3721 | VarDecl *ConditionVar = 0; |
| 3722 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3723 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3724 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3725 | getDerived().TransformDefinition( |
| 3726 | S->getConditionVariable()->getLocation(), |
| 3727 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3728 | if (!ConditionVar) |
| 3729 | return SemaRef.StmtError(); |
| 3730 | } else { |
| 3731 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3732 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3733 | if (Cond.isInvalid()) |
| 3734 | return SemaRef.StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3735 | |
| 3736 | if (S->getCond()) { |
| 3737 | // Convert the condition to a boolean value. |
| 3738 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3739 | S->getForLoc(), |
| 3740 | move(Cond)); |
| 3741 | if (CondE.isInvalid()) |
| 3742 | return getSema().StmtError(); |
| 3743 | |
| 3744 | Cond = move(CondE); |
| 3745 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3746 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3748 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3749 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3750 | return SemaRef.StmtError(); |
| 3751 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3752 | // Transform the increment |
| 3753 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3754 | if (Inc.isInvalid()) |
| 3755 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3757 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3758 | if (S->getInc() && !FullInc->get()) |
| 3759 | return SemaRef.StmtError(); |
| 3760 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3761 | // Transform the body |
| 3762 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3763 | if (Body.isInvalid()) |
| 3764 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3765 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3766 | if (!getDerived().AlwaysRebuild() && |
| 3767 | Init.get() == S->getInit() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3768 | FullCond->get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3769 | Inc.get() == S->getInc() && |
| 3770 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3771 | return SemaRef.Owned(S->Retain()); |
| 3772 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3773 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3774 | move(Init), FullCond, ConditionVar, |
| 3775 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | Sema::OwningStmtResult |
| 3780 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3781 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3783 | S->getLabel()); |
| 3784 | } |
| 3785 | |
| 3786 | template<typename Derived> |
| 3787 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3789 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3790 | if (Target.isInvalid()) |
| 3791 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3793 | if (!getDerived().AlwaysRebuild() && |
| 3794 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3796 | |
| 3797 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3798 | move(Target)); |
| 3799 | } |
| 3800 | |
| 3801 | template<typename Derived> |
| 3802 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3803 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3804 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3806 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3807 | template<typename Derived> |
| 3808 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3810 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3811 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3812 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3813 | template<typename Derived> |
| 3814 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3816 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3817 | if (Result.isInvalid()) |
| 3818 | return SemaRef.StmtError(); |
| 3819 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3820 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3821 | // to tell whether the return type of the function has changed. |
| 3822 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3823 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3824 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3825 | template<typename Derived> |
| 3826 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3827 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3828 | bool DeclChanged = false; |
| 3829 | llvm::SmallVector<Decl *, 4> Decls; |
| 3830 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3831 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3832 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3833 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3834 | if (!Transformed) |
| 3835 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3837 | if (Transformed != *D) |
| 3838 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3840 | Decls.push_back(Transformed); |
| 3841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3842 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3843 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | return SemaRef.Owned(S->Retain()); |
| 3845 | |
| 3846 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3847 | S->getStartLoc(), S->getEndLoc()); |
| 3848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3850 | template<typename Derived> |
| 3851 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3853 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3854 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | template<typename Derived> |
| 3858 | Sema::OwningStmtResult |
| 3859 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3860 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3861 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3862 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3863 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3864 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3865 | OwningExprResult AsmString(SemaRef); |
| 3866 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3867 | |
| 3868 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3869 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3870 | // Go through the outputs. |
| 3871 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3872 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3873 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3874 | // No need to transform the constraint literal. |
| 3875 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3876 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3877 | // Transform the output expr. |
| 3878 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3879 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3880 | if (Result.isInvalid()) |
| 3881 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3882 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3883 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3884 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3885 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3886 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3887 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3888 | // Go through the inputs. |
| 3889 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3890 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3891 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3892 | // No need to transform the constraint literal. |
| 3893 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3894 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3895 | // Transform the input expr. |
| 3896 | Expr *InputExpr = S->getInputExpr(I); |
| 3897 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3898 | if (Result.isInvalid()) |
| 3899 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3900 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3901 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3902 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3903 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3904 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3905 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3906 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3907 | return SemaRef.Owned(S->Retain()); |
| 3908 | |
| 3909 | // Go through the clobbers. |
| 3910 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3911 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3912 | |
| 3913 | // No need to transform the asm string literal. |
| 3914 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3915 | |
| 3916 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3917 | S->isSimple(), |
| 3918 | S->isVolatile(), |
| 3919 | S->getNumOutputs(), |
| 3920 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3921 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3922 | move_arg(Constraints), |
| 3923 | move_arg(Exprs), |
| 3924 | move(AsmString), |
| 3925 | move_arg(Clobbers), |
| 3926 | S->getRParenLoc(), |
| 3927 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | |
| 3931 | template<typename Derived> |
| 3932 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3933 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3934 | // Transform the body of the @try. |
| 3935 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3936 | if (TryBody.isInvalid()) |
| 3937 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3938 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3939 | // Transform the @catch statements (if present). |
| 3940 | bool AnyCatchChanged = false; |
| 3941 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3942 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3943 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3944 | if (Catch.isInvalid()) |
| 3945 | return SemaRef.StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3946 | if (Catch.get() != S->getCatchStmt(I)) |
| 3947 | AnyCatchChanged = true; |
| 3948 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3949 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3950 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3951 | // Transform the @finally statement (if present). |
| 3952 | OwningStmtResult Finally(SemaRef); |
| 3953 | if (S->getFinallyStmt()) { |
| 3954 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3955 | if (Finally.isInvalid()) |
| 3956 | return SemaRef.StmtError(); |
| 3957 | } |
| 3958 | |
| 3959 | // If nothing changed, just retain this statement. |
| 3960 | if (!getDerived().AlwaysRebuild() && |
| 3961 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3962 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3963 | Finally.get() == S->getFinallyStmt()) |
| 3964 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3965 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3966 | // Build a new statement. |
| 3967 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3968 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3969 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3970 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3971 | template<typename Derived> |
| 3972 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3973 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3974 | // Transform the @catch parameter, if there is one. |
| 3975 | VarDecl *Var = 0; |
| 3976 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3977 | TypeSourceInfo *TSInfo = 0; |
| 3978 | if (FromVar->getTypeSourceInfo()) { |
| 3979 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3980 | if (!TSInfo) |
| 3981 | return SemaRef.StmtError(); |
| 3982 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3984 | QualType T; |
| 3985 | if (TSInfo) |
| 3986 | T = TSInfo->getType(); |
| 3987 | else { |
| 3988 | T = getDerived().TransformType(FromVar->getType()); |
| 3989 | if (T.isNull()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3990 | return SemaRef.StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3991 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3993 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3994 | if (!Var) |
| 3995 | return SemaRef.StmtError(); |
| 3996 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3998 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3999 | if (Body.isInvalid()) |
| 4000 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4001 | |
| 4002 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4003 | S->getRParenLoc(), |
| 4004 | Var, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4005 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4006 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4007 | template<typename Derived> |
| 4008 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4009 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4010 | // Transform the body. |
| 4011 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 4012 | if (Body.isInvalid()) |
| 4013 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4014 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4015 | // If nothing changed, just retain this statement. |
| 4016 | if (!getDerived().AlwaysRebuild() && |
| 4017 | Body.get() == S->getFinallyBody()) |
| 4018 | return SemaRef.Owned(S->Retain()); |
| 4019 | |
| 4020 | // Build a new statement. |
| 4021 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 4022 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4024 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4025 | template<typename Derived> |
| 4026 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4028 | OwningExprResult Operand(SemaRef); |
| 4029 | if (S->getThrowExpr()) { |
| 4030 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 4031 | if (Operand.isInvalid()) |
| 4032 | return getSema().StmtError(); |
| 4033 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4034 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4035 | if (!getDerived().AlwaysRebuild() && |
| 4036 | Operand.get() == S->getThrowExpr()) |
| 4037 | return getSema().Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4038 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4039 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4040 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4042 | template<typename Derived> |
| 4043 | Sema::OwningStmtResult |
| 4044 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4045 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4046 | // Transform the object we are locking. |
| 4047 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 4048 | if (Object.isInvalid()) |
| 4049 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4051 | // Transform the body. |
| 4052 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 4053 | if (Body.isInvalid()) |
| 4054 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4055 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4056 | // If nothing change, just retain the current statement. |
| 4057 | if (!getDerived().AlwaysRebuild() && |
| 4058 | Object.get() == S->getSynchExpr() && |
| 4059 | Body.get() == S->getSynchBody()) |
| 4060 | return SemaRef.Owned(S->Retain()); |
| 4061 | |
| 4062 | // Build a new statement. |
| 4063 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 4064 | move(Object), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | template<typename Derived> |
| 4068 | Sema::OwningStmtResult |
| 4069 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4070 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4071 | // Transform the element statement. |
| 4072 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 4073 | if (Element.isInvalid()) |
| 4074 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4075 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4076 | // Transform the collection expression. |
| 4077 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 4078 | if (Collection.isInvalid()) |
| 4079 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4081 | // Transform the body. |
| 4082 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 4083 | if (Body.isInvalid()) |
| 4084 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4085 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4086 | // If nothing changed, just retain this statement. |
| 4087 | if (!getDerived().AlwaysRebuild() && |
| 4088 | Element.get() == S->getElement() && |
| 4089 | Collection.get() == S->getCollection() && |
| 4090 | Body.get() == S->getBody()) |
| 4091 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4093 | // Build a new statement. |
| 4094 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4095 | /*FIXME:*/S->getForLoc(), |
| 4096 | move(Element), |
| 4097 | move(Collection), |
| 4098 | S->getRParenLoc(), |
| 4099 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | |
| 4103 | template<typename Derived> |
| 4104 | Sema::OwningStmtResult |
| 4105 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4106 | // Transform the exception declaration, if any. |
| 4107 | VarDecl *Var = 0; |
| 4108 | if (S->getExceptionDecl()) { |
| 4109 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4110 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4111 | ExceptionDecl->getDeclName()); |
| 4112 | |
| 4113 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4114 | if (T.isNull()) |
| 4115 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4117 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4118 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4119 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4120 | ExceptionDecl->getIdentifier(), |
| 4121 | ExceptionDecl->getLocation(), |
| 4122 | /*FIXME: Inaccurate*/ |
| 4123 | SourceRange(ExceptionDecl->getLocation())); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 4124 | if (!Var || Var->isInvalidDecl()) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4125 | return SemaRef.StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4126 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4127 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4128 | // Transform the actual exception handler. |
| 4129 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 4130 | if (Handler.isInvalid()) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4131 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4133 | if (!getDerived().AlwaysRebuild() && |
| 4134 | !Var && |
| 4135 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4137 | |
| 4138 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4139 | Var, |
| 4140 | move(Handler)); |
| 4141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4142 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4143 | template<typename Derived> |
| 4144 | Sema::OwningStmtResult |
| 4145 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4146 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4148 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4149 | if (TryBlock.isInvalid()) |
| 4150 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4151 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4152 | // Transform the handlers. |
| 4153 | bool HandlerChanged = false; |
| 4154 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4155 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4156 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4157 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4158 | if (Handler.isInvalid()) |
| 4159 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4161 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4162 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4164 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4165 | if (!getDerived().AlwaysRebuild() && |
| 4166 | TryBlock.get() == S->getTryBlock() && |
| 4167 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4169 | |
| 4170 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4171 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4172 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4174 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4175 | // Expression transformation |
| 4176 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | template<typename Derived> |
| 4178 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4179 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4180 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4182 | |
| 4183 | template<typename Derived> |
| 4184 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4185 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4186 | NestedNameSpecifier *Qualifier = 0; |
| 4187 | if (E->getQualifier()) { |
| 4188 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4189 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4190 | if (!Qualifier) |
| 4191 | return SemaRef.ExprError(); |
| 4192 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4193 | |
| 4194 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4195 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4196 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4197 | if (!ND) |
| 4198 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4200 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4201 | Qualifier == E->getQualifier() && |
| 4202 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4203 | !E->hasExplicitTemplateArgumentList()) { |
| 4204 | |
| 4205 | // Mark it referenced in the new context regardless. |
| 4206 | // FIXME: this is a bit instantiation-specific. |
| 4207 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4208 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4210 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4211 | |
| 4212 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4213 | if (E->hasExplicitTemplateArgumentList()) { |
| 4214 | TemplateArgs = &TransArgs; |
| 4215 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4216 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4217 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4218 | TemplateArgumentLoc Loc; |
| 4219 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4220 | return SemaRef.ExprError(); |
| 4221 | TransArgs.addArgument(Loc); |
| 4222 | } |
| 4223 | } |
| 4224 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4225 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4226 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4231 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4232 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4233 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4234 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4237 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4242 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4243 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4244 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4245 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4248 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4249 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4251 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4252 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4253 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4255 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4256 | return SemaRef.Owned(E->Retain()); |
| 4257 | } |
| 4258 | |
| 4259 | template<typename Derived> |
| 4260 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4261 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4263 | if (SubExpr.isInvalid()) |
| 4264 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4265 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4266 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4267 | return SemaRef.Owned(E->Retain()); |
| 4268 | |
| 4269 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4270 | E->getRParen()); |
| 4271 | } |
| 4272 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4273 | template<typename Derived> |
| 4274 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4275 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4276 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4277 | if (SubExpr.isInvalid()) |
| 4278 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4280 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4281 | return SemaRef.Owned(E->Retain()); |
| 4282 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4283 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4284 | E->getOpcode(), |
| 4285 | move(SubExpr)); |
| 4286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4287 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4288 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4289 | Sema::OwningExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4290 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4291 | // Transform the type. |
| 4292 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4293 | if (!Type) |
| 4294 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4295 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4296 | // Transform all of the components into components similar to what the |
| 4297 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4298 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4299 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4300 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4301 | // template code that we don't care. |
| 4302 | bool ExprChanged = false; |
| 4303 | typedef Action::OffsetOfComponent Component; |
| 4304 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4305 | llvm::SmallVector<Component, 4> Components; |
| 4306 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4307 | const Node &ON = E->getComponent(I); |
| 4308 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4309 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4310 | Comp.LocStart = ON.getRange().getBegin(); |
| 4311 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4312 | switch (ON.getKind()) { |
| 4313 | case Node::Array: { |
| 4314 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4315 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4316 | if (Index.isInvalid()) |
| 4317 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4319 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4320 | Comp.isBrackets = true; |
| 4321 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4322 | break; |
| 4323 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4324 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4325 | case Node::Field: |
| 4326 | case Node::Identifier: |
| 4327 | Comp.isBrackets = false; |
| 4328 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4329 | if (!Comp.U.IdentInfo) |
| 4330 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4331 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4332 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4333 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4334 | case Node::Base: |
| 4335 | // Will be recomputed during the rebuild. |
| 4336 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4337 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4338 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4339 | Components.push_back(Comp); |
| 4340 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4341 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4342 | // If nothing changed, retain the existing expression. |
| 4343 | if (!getDerived().AlwaysRebuild() && |
| 4344 | Type == E->getTypeSourceInfo() && |
| 4345 | !ExprChanged) |
| 4346 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4348 | // Build a new offsetof expression. |
| 4349 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4350 | Components.data(), Components.size(), |
| 4351 | E->getRParenLoc()); |
| 4352 | } |
| 4353 | |
| 4354 | template<typename Derived> |
| 4355 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4356 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4357 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4358 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4359 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4360 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4361 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4364 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4365 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4367 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4368 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4369 | E->getSourceRange()); |
| 4370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | // C++0x [expr.sizeof]p1: |
| 4375 | // The operand is either an expression, which is an unevaluated operand |
| 4376 | // [...] |
| 4377 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4380 | if (SubExpr.isInvalid()) |
| 4381 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4382 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4383 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4384 | return SemaRef.Owned(E->Retain()); |
| 4385 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4386 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4387 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4388 | E->isSizeOf(), |
| 4389 | E->getSourceRange()); |
| 4390 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4394 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4395 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4396 | if (LHS.isInvalid()) |
| 4397 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4398 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4399 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4400 | if (RHS.isInvalid()) |
| 4401 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
| 4403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | if (!getDerived().AlwaysRebuild() && |
| 4405 | LHS.get() == E->getLHS() && |
| 4406 | RHS.get() == E->getRHS()) |
| 4407 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4410 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4411 | move(RHS), |
| 4412 | E->getRBracketLoc()); |
| 4413 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | |
| 4415 | template<typename Derived> |
| 4416 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4417 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4418 | // Transform the callee. |
| 4419 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4420 | if (Callee.isInvalid()) |
| 4421 | return SemaRef.ExprError(); |
| 4422 | |
| 4423 | // Transform arguments. |
| 4424 | bool ArgChanged = false; |
| 4425 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4426 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4427 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4428 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4429 | if (Arg.isInvalid()) |
| 4430 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4431 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | // FIXME: Wrong source location information for the ','. |
| 4433 | FakeCommaLocs.push_back( |
| 4434 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | |
| 4436 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | Args.push_back(Arg.takeAs<Expr>()); |
| 4438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | if (!getDerived().AlwaysRebuild() && |
| 4441 | Callee.get() == E->getCallee() && |
| 4442 | !ArgChanged) |
| 4443 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4444 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4445 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4446 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4448 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4449 | move_arg(Args), |
| 4450 | FakeCommaLocs.data(), |
| 4451 | E->getRParenLoc()); |
| 4452 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4453 | |
| 4454 | template<typename Derived> |
| 4455 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4456 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4457 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4458 | if (Base.isInvalid()) |
| 4459 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4461 | NestedNameSpecifier *Qualifier = 0; |
| 4462 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4463 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4464 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4465 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4466 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4467 | return SemaRef.ExprError(); |
| 4468 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4470 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4471 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4472 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4473 | if (!Member) |
| 4474 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4475 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4476 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4477 | if (FoundDecl == E->getMemberDecl()) { |
| 4478 | FoundDecl = Member; |
| 4479 | } else { |
| 4480 | FoundDecl = cast_or_null<NamedDecl>( |
| 4481 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4482 | if (!FoundDecl) |
| 4483 | return SemaRef.ExprError(); |
| 4484 | } |
| 4485 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4486 | if (!getDerived().AlwaysRebuild() && |
| 4487 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4488 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4489 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4490 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4491 | !E->hasExplicitTemplateArgumentList()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4492 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4493 | // Mark it referenced in the new context regardless. |
| 4494 | // FIXME: this is a bit instantiation-specific. |
| 4495 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4497 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4499 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4500 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4501 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4502 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4503 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4504 | TemplateArgumentLoc Loc; |
| 4505 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4506 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4507 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4508 | } |
| 4509 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | // FIXME: Bogus source location for the operator |
| 4512 | SourceLocation FakeOperatorLoc |
| 4513 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4514 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4515 | // FIXME: to do this check properly, we will need to preserve the |
| 4516 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4517 | // base (and therefore couldn't do the check) and a |
| 4518 | // nested-name-qualifier (and therefore could do the lookup). |
| 4519 | NamedDecl *FirstQualifierInScope = 0; |
| 4520 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4522 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4523 | Qualifier, |
| 4524 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4525 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4526 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4527 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4528 | (E->hasExplicitTemplateArgumentList() |
| 4529 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4530 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4533 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4535 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4536 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4537 | if (LHS.isInvalid()) |
| 4538 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4541 | if (RHS.isInvalid()) |
| 4542 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4544 | if (!getDerived().AlwaysRebuild() && |
| 4545 | LHS.get() == E->getLHS() && |
| 4546 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | return SemaRef.Owned(E->Retain()); |
| 4548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4550 | move(LHS), move(RHS)); |
| 4551 | } |
| 4552 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4553 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4554 | Sema::OwningExprResult |
| 4555 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4556 | CompoundAssignOperator *E) { |
| 4557 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4558 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4559 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4560 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4562 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4563 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4564 | if (Cond.isInvalid()) |
| 4565 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4568 | if (LHS.isInvalid()) |
| 4569 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4571 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4572 | if (RHS.isInvalid()) |
| 4573 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | if (!getDerived().AlwaysRebuild() && |
| 4576 | Cond.get() == E->getCond() && |
| 4577 | LHS.get() == E->getLHS() && |
| 4578 | RHS.get() == E->getRHS()) |
| 4579 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
| 4581 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4582 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4584 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4585 | move(RHS)); |
| 4586 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4587 | |
| 4588 | template<typename Derived> |
| 4589 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4590 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4591 | // Implicit casts are eliminated during transformation, since they |
| 4592 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4593 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4596 | template<typename Derived> |
| 4597 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4598 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4599 | TypeSourceInfo *OldT; |
| 4600 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | { |
| 4602 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4605 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4607 | OldT = E->getTypeInfoAsWritten(); |
| 4608 | NewT = getDerived().TransformType(OldT); |
| 4609 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4610 | return SemaRef.ExprError(); |
| 4611 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4613 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4614 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | if (SubExpr.isInvalid()) |
| 4616 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4617 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4618 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4619 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4620 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | return SemaRef.Owned(E->Retain()); |
| 4622 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4623 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4624 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | E->getRParenLoc(), |
| 4626 | move(SubExpr)); |
| 4627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4628 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4629 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4630 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4631 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4632 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4633 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4634 | if (!NewT) |
| 4635 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4636 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4638 | if (Init.isInvalid()) |
| 4639 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4642 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4645 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4646 | // Note: the expression type doesn't necessarily match the |
| 4647 | // type-as-written, but that's okay, because it should always be |
| 4648 | // derivable from the initializer. |
| 4649 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4650 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4652 | move(Init)); |
| 4653 | } |
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 | template<typename Derived> |
| 4656 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4657 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4659 | if (Base.isInvalid()) |
| 4660 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4662 | if (!getDerived().AlwaysRebuild() && |
| 4663 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | return SemaRef.Owned(E->Retain()); |
| 4665 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4668 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4669 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4670 | E->getAccessorLoc(), |
| 4671 | E->getAccessor()); |
| 4672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4674 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4676 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4677 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4678 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4679 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4680 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4681 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4682 | if (Init.isInvalid()) |
| 4683 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4684 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4685 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4686 | Inits.push_back(Init.takeAs<Expr>()); |
| 4687 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4690 | return SemaRef.Owned(E->Retain()); |
| 4691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4692 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4693 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4694 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4696 | template<typename Derived> |
| 4697 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4698 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4699 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4701 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4703 | if (Init.isInvalid()) |
| 4704 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4706 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4707 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4708 | bool ExprChanged = false; |
| 4709 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4710 | DEnd = E->designators_end(); |
| 4711 | D != DEnd; ++D) { |
| 4712 | if (D->isFieldDesignator()) { |
| 4713 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4714 | D->getDotLoc(), |
| 4715 | D->getFieldLoc())); |
| 4716 | continue; |
| 4717 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | if (D->isArrayDesignator()) { |
| 4720 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4721 | if (Index.isInvalid()) |
| 4722 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | |
| 4724 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4726 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4727 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4728 | ArrayExprs.push_back(Index.release()); |
| 4729 | continue; |
| 4730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4732 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4733 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4734 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4735 | if (Start.isInvalid()) |
| 4736 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4737 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4738 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4739 | if (End.isInvalid()) |
| 4740 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4741 | |
| 4742 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4743 | End.get(), |
| 4744 | D->getLBracketLoc(), |
| 4745 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4748 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4750 | ArrayExprs.push_back(Start.release()); |
| 4751 | ArrayExprs.push_back(End.release()); |
| 4752 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4754 | if (!getDerived().AlwaysRebuild() && |
| 4755 | Init.get() == E->getInit() && |
| 4756 | !ExprChanged) |
| 4757 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4759 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4760 | E->getEqualOrColonLoc(), |
| 4761 | E->usesGNUSyntax(), move(Init)); |
| 4762 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4766 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4767 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4768 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4769 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4770 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4771 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4772 | QualType T = getDerived().TransformType(E->getType()); |
| 4773 | if (T.isNull()) |
| 4774 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4775 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | if (!getDerived().AlwaysRebuild() && |
| 4777 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4778 | return SemaRef.Owned(E->Retain()); |
| 4779 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4781 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4783 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4784 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4785 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame^] | 4786 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 4787 | if (!TInfo) |
| 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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4791 | if (SubExpr.isInvalid()) |
| 4792 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 4795 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4796 | SubExpr.get() == E->getSubExpr()) |
| 4797 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4798 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 4800 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4805 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4806 | bool ArgumentChanged = false; |
| 4807 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4808 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4809 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4810 | if (Init.isInvalid()) |
| 4811 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4812 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4813 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4814 | Inits.push_back(Init.takeAs<Expr>()); |
| 4815 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4818 | move_arg(Inits), |
| 4819 | E->getRParenLoc()); |
| 4820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | /// \brief Transform an address-of-label expression. |
| 4823 | /// |
| 4824 | /// By default, the transformation of an address-of-label expression always |
| 4825 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4826 | /// the corresponding label statement by semantic analysis. |
| 4827 | template<typename Derived> |
| 4828 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4829 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4831 | E->getLabel()); |
| 4832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | |
| 4834 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4835 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4836 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4839 | if (SubStmt.isInvalid()) |
| 4840 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4841 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4842 | if (!getDerived().AlwaysRebuild() && |
| 4843 | SubStmt.get() == E->getSubStmt()) |
| 4844 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4845 | |
| 4846 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4847 | move(SubStmt), |
| 4848 | E->getRParenLoc()); |
| 4849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4850 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4851 | template<typename Derived> |
| 4852 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4853 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4854 | TypeSourceInfo *TInfo1; |
| 4855 | TypeSourceInfo *TInfo2; |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame^] | 4856 | |
| 4857 | TInfo1 = getDerived().TransformType(E->getArgTInfo1()); |
| 4858 | if (!TInfo1) |
| 4859 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame^] | 4861 | TInfo2 = getDerived().TransformType(E->getArgTInfo2()); |
| 4862 | if (!TInfo2) |
| 4863 | return SemaRef.ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4864 | |
| 4865 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4866 | TInfo1 == E->getArgTInfo1() && |
| 4867 | TInfo2 == E->getArgTInfo2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4868 | return SemaRef.Owned(E->Retain()); |
| 4869 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4870 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4871 | TInfo1, TInfo2, |
| 4872 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4873 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4875 | template<typename Derived> |
| 4876 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4877 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4879 | if (Cond.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 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4883 | if (LHS.isInvalid()) |
| 4884 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4885 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4886 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4887 | if (RHS.isInvalid()) |
| 4888 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4889 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4890 | if (!getDerived().AlwaysRebuild() && |
| 4891 | Cond.get() == E->getCond() && |
| 4892 | LHS.get() == E->getLHS() && |
| 4893 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4894 | return SemaRef.Owned(E->Retain()); |
| 4895 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4897 | move(Cond), move(LHS), move(RHS), |
| 4898 | E->getRParenLoc()); |
| 4899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4901 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4902 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4903 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4904 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | template<typename Derived> |
| 4908 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4909 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4910 | switch (E->getOperator()) { |
| 4911 | case OO_New: |
| 4912 | case OO_Delete: |
| 4913 | case OO_Array_New: |
| 4914 | case OO_Array_Delete: |
| 4915 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4916 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4917 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4918 | case OO_Call: { |
| 4919 | // This is a call to an object's operator(). |
| 4920 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4921 | |
| 4922 | // Transform the object itself. |
| 4923 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4924 | if (Object.isInvalid()) |
| 4925 | return SemaRef.ExprError(); |
| 4926 | |
| 4927 | // FIXME: Poor location information |
| 4928 | SourceLocation FakeLParenLoc |
| 4929 | = SemaRef.PP.getLocForEndOfToken( |
| 4930 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4931 | |
| 4932 | // Transform the call arguments. |
| 4933 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4934 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4935 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4936 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4937 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4938 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4939 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4940 | if (Arg.isInvalid()) |
| 4941 | return SemaRef.ExprError(); |
| 4942 | |
| 4943 | // FIXME: Poor source location information. |
| 4944 | SourceLocation FakeCommaLoc |
| 4945 | = SemaRef.PP.getLocForEndOfToken( |
| 4946 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4947 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4948 | Args.push_back(Arg.release()); |
| 4949 | } |
| 4950 | |
| 4951 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4952 | move_arg(Args), |
| 4953 | FakeCommaLocs.data(), |
| 4954 | E->getLocEnd()); |
| 4955 | } |
| 4956 | |
| 4957 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4958 | case OO_##Name: |
| 4959 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4960 | #include "clang/Basic/OperatorKinds.def" |
| 4961 | case OO_Subscript: |
| 4962 | // Handled below. |
| 4963 | break; |
| 4964 | |
| 4965 | case OO_Conditional: |
| 4966 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4967 | return SemaRef.ExprError(); |
| 4968 | |
| 4969 | case OO_None: |
| 4970 | case NUM_OVERLOADED_OPERATORS: |
| 4971 | llvm_unreachable("not an overloaded operator?"); |
| 4972 | return SemaRef.ExprError(); |
| 4973 | } |
| 4974 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4975 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4976 | if (Callee.isInvalid()) |
| 4977 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4979 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4980 | if (First.isInvalid()) |
| 4981 | return SemaRef.ExprError(); |
| 4982 | |
| 4983 | OwningExprResult Second(SemaRef); |
| 4984 | if (E->getNumArgs() == 2) { |
| 4985 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4986 | if (Second.isInvalid()) |
| 4987 | return SemaRef.ExprError(); |
| 4988 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4989 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4990 | if (!getDerived().AlwaysRebuild() && |
| 4991 | Callee.get() == E->getCallee() && |
| 4992 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4994 | return SemaRef.Owned(E->Retain()); |
| 4995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4996 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4997 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4998 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4999 | move(First), |
| 5000 | move(Second)); |
| 5001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5003 | template<typename Derived> |
| 5004 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5005 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5006 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5007 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5008 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5009 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5011 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5012 | TypeSourceInfo *OldT; |
| 5013 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5014 | { |
| 5015 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5017 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5018 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5020 | OldT = E->getTypeInfoAsWritten(); |
| 5021 | NewT = getDerived().TransformType(OldT); |
| 5022 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5023 | return SemaRef.ExprError(); |
| 5024 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5025 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5026 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5027 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | if (SubExpr.isInvalid()) |
| 5029 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5030 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5031 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5032 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5033 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5034 | return SemaRef.Owned(E->Retain()); |
| 5035 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5036 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5037 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5038 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5039 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 5040 | SourceLocation FakeRParenLoc |
| 5041 | = SemaRef.PP.getLocForEndOfToken( |
| 5042 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5043 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5044 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5045 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5046 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5047 | FakeRAngleLoc, |
| 5048 | FakeRAngleLoc, |
| 5049 | move(SubExpr), |
| 5050 | FakeRParenLoc); |
| 5051 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5052 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5053 | template<typename Derived> |
| 5054 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5055 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5056 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5058 | |
| 5059 | template<typename Derived> |
| 5060 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5061 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5062 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5065 | template<typename Derived> |
| 5066 | Sema::OwningExprResult |
| 5067 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5068 | CXXReinterpretCastExpr *E) { |
| 5069 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5071 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5072 | template<typename Derived> |
| 5073 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5074 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5075 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | template<typename Derived> |
| 5079 | Sema::OwningExprResult |
| 5080 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5081 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5082 | TypeSourceInfo *OldT; |
| 5083 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5084 | { |
| 5085 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5086 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5087 | OldT = E->getTypeInfoAsWritten(); |
| 5088 | NewT = getDerived().TransformType(OldT); |
| 5089 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5090 | return SemaRef.ExprError(); |
| 5091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5092 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5093 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5094 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5095 | if (SubExpr.isInvalid()) |
| 5096 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5098 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5099 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | return SemaRef.Owned(E->Retain()); |
| 5102 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5103 | // FIXME: The end of the type's source range is wrong |
| 5104 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5105 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5106 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5107 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5108 | move(SubExpr), |
| 5109 | E->getRParenLoc()); |
| 5110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5112 | template<typename Derived> |
| 5113 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5114 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5116 | TypeSourceInfo *TInfo |
| 5117 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5118 | if (!TInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5119 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5120 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5122 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5123 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5125 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5126 | E->getLocStart(), |
| 5127 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5128 | E->getLocEnd()); |
| 5129 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5131 | // We don't know whether the expression is potentially evaluated until |
| 5132 | // after we perform semantic analysis, so the expression is potentially |
| 5133 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5135 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5137 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5138 | if (SubExpr.isInvalid()) |
| 5139 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5141 | if (!getDerived().AlwaysRebuild() && |
| 5142 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5143 | return SemaRef.Owned(E->Retain()); |
| 5144 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5145 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5146 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5147 | move(SubExpr), |
| 5148 | E->getLocEnd()); |
| 5149 | } |
| 5150 | |
| 5151 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5152 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5153 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5155 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5156 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5157 | template<typename Derived> |
| 5158 | Sema::OwningExprResult |
| 5159 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5160 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5161 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5164 | template<typename Derived> |
| 5165 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5166 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5167 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5168 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5169 | QualType T = getDerived().TransformType(E->getType()); |
| 5170 | if (T.isNull()) |
| 5171 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5173 | if (!getDerived().AlwaysRebuild() && |
| 5174 | T == E->getType()) |
| 5175 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5177 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5180 | template<typename Derived> |
| 5181 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5182 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5183 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5184 | if (SubExpr.isInvalid()) |
| 5185 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5187 | if (!getDerived().AlwaysRebuild() && |
| 5188 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5190 | |
| 5191 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5194 | template<typename Derived> |
| 5195 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5196 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5198 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5199 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5200 | if (!Param) |
| 5201 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5203 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | Param == E->getParam()) |
| 5205 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5206 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5207 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5208 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5209 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5210 | template<typename Derived> |
| 5211 | Sema::OwningExprResult |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 5212 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5213 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5214 | |
| 5215 | QualType T = getDerived().TransformType(E->getType()); |
| 5216 | if (T.isNull()) |
| 5217 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | if (!getDerived().AlwaysRebuild() && |
| 5220 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5221 | return SemaRef.Owned(E->Retain()); |
| 5222 | |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 5223 | return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(), |
| 5224 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5225 | T, |
| 5226 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | template<typename Derived> |
| 5230 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5231 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5232 | // Transform the type that we're allocating |
| 5233 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5234 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5235 | if (AllocType.isNull()) |
| 5236 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5237 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5238 | // Transform the size of the array we're allocating (if any). |
| 5239 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5240 | if (ArraySize.isInvalid()) |
| 5241 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5243 | // Transform the placement arguments (if any). |
| 5244 | bool ArgumentChanged = false; |
| 5245 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5246 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5247 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5248 | if (Arg.isInvalid()) |
| 5249 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5250 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5251 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5252 | PlacementArgs.push_back(Arg.take()); |
| 5253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5254 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5255 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5256 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5257 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
Douglas Gregor | 1b30b3c | 2010-05-26 07:10:06 +0000 | [diff] [blame] | 5258 | if (getDerived().DropCallArgument(E->getConstructorArg(I))) |
| 5259 | break; |
| 5260 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5261 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5262 | if (Arg.isInvalid()) |
| 5263 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5265 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5266 | ConstructorArgs.push_back(Arg.take()); |
| 5267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5268 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5269 | // Transform constructor, new operator, and delete operator. |
| 5270 | CXXConstructorDecl *Constructor = 0; |
| 5271 | if (E->getConstructor()) { |
| 5272 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5273 | getDerived().TransformDecl(E->getLocStart(), |
| 5274 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5275 | if (!Constructor) |
| 5276 | return SemaRef.ExprError(); |
| 5277 | } |
| 5278 | |
| 5279 | FunctionDecl *OperatorNew = 0; |
| 5280 | if (E->getOperatorNew()) { |
| 5281 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5282 | getDerived().TransformDecl(E->getLocStart(), |
| 5283 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5284 | if (!OperatorNew) |
| 5285 | return SemaRef.ExprError(); |
| 5286 | } |
| 5287 | |
| 5288 | FunctionDecl *OperatorDelete = 0; |
| 5289 | if (E->getOperatorDelete()) { |
| 5290 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5291 | getDerived().TransformDecl(E->getLocStart(), |
| 5292 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5293 | if (!OperatorDelete) |
| 5294 | return SemaRef.ExprError(); |
| 5295 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5296 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5297 | if (!getDerived().AlwaysRebuild() && |
| 5298 | AllocType == E->getAllocatedType() && |
| 5299 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5300 | Constructor == E->getConstructor() && |
| 5301 | OperatorNew == E->getOperatorNew() && |
| 5302 | OperatorDelete == E->getOperatorDelete() && |
| 5303 | !ArgumentChanged) { |
| 5304 | // Mark any declarations we need as referenced. |
| 5305 | // FIXME: instantiation-specific. |
| 5306 | if (Constructor) |
| 5307 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5308 | if (OperatorNew) |
| 5309 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5310 | if (OperatorDelete) |
| 5311 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5312 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5313 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5314 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5315 | if (!ArraySize.get()) { |
| 5316 | // If no array size was specified, but the new expression was |
| 5317 | // instantiated with an array type (e.g., "new T" where T is |
| 5318 | // instantiated with "int[4]"), extract the outer bound from the |
| 5319 | // array type as our array size. We do this with constant and |
| 5320 | // dependently-sized array types. |
| 5321 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5322 | if (!ArrayT) { |
| 5323 | // Do nothing |
| 5324 | } else if (const ConstantArrayType *ConsArrayT |
| 5325 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5326 | ArraySize |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5327 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5328 | ConsArrayT->getSize(), |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5329 | SemaRef.Context.getSizeType(), |
| 5330 | /*FIXME:*/E->getLocStart())); |
| 5331 | AllocType = ConsArrayT->getElementType(); |
| 5332 | } else if (const DependentSizedArrayType *DepArrayT |
| 5333 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5334 | if (DepArrayT->getSizeExpr()) { |
| 5335 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5336 | AllocType = DepArrayT->getElementType(); |
| 5337 | } |
| 5338 | } |
| 5339 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5340 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5341 | E->isGlobalNew(), |
| 5342 | /*FIXME:*/E->getLocStart(), |
| 5343 | move_arg(PlacementArgs), |
| 5344 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 5345 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5346 | AllocType, |
| 5347 | /*FIXME:*/E->getLocStart(), |
| 5348 | /*FIXME:*/SourceRange(), |
| 5349 | move(ArraySize), |
| 5350 | /*FIXME:*/E->getLocStart(), |
| 5351 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5353 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5354 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5355 | template<typename Derived> |
| 5356 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5357 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5358 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5359 | if (Operand.isInvalid()) |
| 5360 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5361 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5362 | // Transform the delete operator, if known. |
| 5363 | FunctionDecl *OperatorDelete = 0; |
| 5364 | if (E->getOperatorDelete()) { |
| 5365 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5366 | getDerived().TransformDecl(E->getLocStart(), |
| 5367 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5368 | if (!OperatorDelete) |
| 5369 | return SemaRef.ExprError(); |
| 5370 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5371 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5372 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5373 | Operand.get() == E->getArgument() && |
| 5374 | OperatorDelete == E->getOperatorDelete()) { |
| 5375 | // Mark any declarations we need as referenced. |
| 5376 | // FIXME: instantiation-specific. |
| 5377 | if (OperatorDelete) |
| 5378 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5379 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5381 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5382 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5383 | E->isGlobalDelete(), |
| 5384 | E->isArrayForm(), |
| 5385 | move(Operand)); |
| 5386 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5387 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5388 | template<typename Derived> |
| 5389 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5390 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5391 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5392 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5393 | if (Base.isInvalid()) |
| 5394 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5395 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5396 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5397 | bool MayBePseudoDestructor = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5398 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5399 | E->getOperatorLoc(), |
| 5400 | E->isArrow()? tok::arrow : tok::period, |
| 5401 | ObjectTypePtr, |
| 5402 | MayBePseudoDestructor); |
| 5403 | if (Base.isInvalid()) |
| 5404 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5405 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5406 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5407 | NestedNameSpecifier *Qualifier |
| 5408 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5409 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5410 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5411 | if (E->getQualifier() && !Qualifier) |
| 5412 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5413 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5414 | PseudoDestructorTypeStorage Destroyed; |
| 5415 | if (E->getDestroyedTypeInfo()) { |
| 5416 | TypeSourceInfo *DestroyedTypeInfo |
| 5417 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5418 | if (!DestroyedTypeInfo) |
| 5419 | return SemaRef.ExprError(); |
| 5420 | Destroyed = DestroyedTypeInfo; |
| 5421 | } else if (ObjectType->isDependentType()) { |
| 5422 | // We aren't likely to be able to resolve the identifier down to a type |
| 5423 | // now anyway, so just retain the identifier. |
| 5424 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5425 | E->getDestroyedTypeLoc()); |
| 5426 | } else { |
| 5427 | // Look for a destructor known with the given name. |
| 5428 | CXXScopeSpec SS; |
| 5429 | if (Qualifier) { |
| 5430 | SS.setScopeRep(Qualifier); |
| 5431 | SS.setRange(E->getQualifierRange()); |
| 5432 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5433 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5434 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5435 | *E->getDestroyedTypeIdentifier(), |
| 5436 | E->getDestroyedTypeLoc(), |
| 5437 | /*Scope=*/0, |
| 5438 | SS, ObjectTypePtr, |
| 5439 | false); |
| 5440 | if (!T) |
| 5441 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5442 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5443 | Destroyed |
| 5444 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5445 | E->getDestroyedTypeLoc()); |
| 5446 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5447 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5448 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5449 | if (E->getScopeTypeInfo()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5450 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5451 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5452 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5453 | return SemaRef.ExprError(); |
| 5454 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5455 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5456 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5457 | E->getOperatorLoc(), |
| 5458 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5459 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5460 | E->getQualifierRange(), |
| 5461 | ScopeTypeInfo, |
| 5462 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5463 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5464 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5465 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5466 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5467 | template<typename Derived> |
| 5468 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5469 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5470 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5471 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5472 | |
| 5473 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5474 | Sema::LookupOrdinaryName); |
| 5475 | |
| 5476 | // Transform all the decls. |
| 5477 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5478 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5479 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5480 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5481 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5482 | if (!InstD) { |
| 5483 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5484 | // This can happen because of dependent hiding. |
| 5485 | if (isa<UsingShadowDecl>(*I)) |
| 5486 | continue; |
| 5487 | else |
| 5488 | return SemaRef.ExprError(); |
| 5489 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5490 | |
| 5491 | // Expand using declarations. |
| 5492 | if (isa<UsingDecl>(InstD)) { |
| 5493 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5494 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5495 | E = UD->shadow_end(); I != E; ++I) |
| 5496 | R.addDecl(*I); |
| 5497 | continue; |
| 5498 | } |
| 5499 | |
| 5500 | R.addDecl(InstD); |
| 5501 | } |
| 5502 | |
| 5503 | // Resolve a kind, but don't do any further analysis. If it's |
| 5504 | // ambiguous, the callee needs to deal with it. |
| 5505 | R.resolveKind(); |
| 5506 | |
| 5507 | // Rebuild the nested-name qualifier, if present. |
| 5508 | CXXScopeSpec SS; |
| 5509 | NestedNameSpecifier *Qualifier = 0; |
| 5510 | if (Old->getQualifier()) { |
| 5511 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5512 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5513 | if (!Qualifier) |
| 5514 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5515 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5516 | SS.setScopeRep(Qualifier); |
| 5517 | SS.setRange(Old->getQualifierRange()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5520 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5521 | CXXRecordDecl *NamingClass |
| 5522 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5523 | Old->getNameLoc(), |
| 5524 | Old->getNamingClass())); |
| 5525 | if (!NamingClass) |
| 5526 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5527 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5528 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | // If we have no template arguments, it's a normal declaration name. |
| 5532 | if (!Old->hasExplicitTemplateArgs()) |
| 5533 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5534 | |
| 5535 | // If we have template arguments, rebuild them, then rebuild the |
| 5536 | // templateid expression. |
| 5537 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5538 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5539 | TemplateArgumentLoc Loc; |
| 5540 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5541 | return SemaRef.ExprError(); |
| 5542 | TransArgs.addArgument(Loc); |
| 5543 | } |
| 5544 | |
| 5545 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5546 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5549 | template<typename Derived> |
| 5550 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5551 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5552 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5554 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5555 | if (T.isNull()) |
| 5556 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5557 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5558 | if (!getDerived().AlwaysRebuild() && |
| 5559 | T == E->getQueriedType()) |
| 5560 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5561 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5562 | // FIXME: Bad location information |
| 5563 | SourceLocation FakeLParenLoc |
| 5564 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5565 | |
| 5566 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5567 | E->getLocStart(), |
| 5568 | /*FIXME:*/FakeLParenLoc, |
| 5569 | T, |
| 5570 | E->getLocEnd()); |
| 5571 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5572 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5573 | template<typename Derived> |
| 5574 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5575 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5576 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5577 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5578 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5579 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5580 | if (!NNS) |
| 5581 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | |
| 5583 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5584 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5585 | if (!Name) |
| 5586 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5587 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5588 | if (!E->hasExplicitTemplateArgs()) { |
| 5589 | if (!getDerived().AlwaysRebuild() && |
| 5590 | NNS == E->getQualifier() && |
| 5591 | Name == E->getDeclName()) |
| 5592 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5594 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5595 | E->getQualifierRange(), |
| 5596 | Name, E->getLocation(), |
| 5597 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5598 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5599 | |
| 5600 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5601 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5602 | TemplateArgumentLoc Loc; |
| 5603 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5604 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5605 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5608 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5609 | E->getQualifierRange(), |
| 5610 | Name, E->getLocation(), |
| 5611 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | template<typename Derived> |
| 5615 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5616 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5617 | // CXXConstructExprs are always implicit, so when we have a |
| 5618 | // 1-argument construction we just transform that argument. |
| 5619 | if (E->getNumArgs() == 1 || |
| 5620 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5621 | return getDerived().TransformExpr(E->getArg(0)); |
| 5622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5624 | |
| 5625 | QualType T = getDerived().TransformType(E->getType()); |
| 5626 | if (T.isNull()) |
| 5627 | return SemaRef.ExprError(); |
| 5628 | |
| 5629 | CXXConstructorDecl *Constructor |
| 5630 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5631 | getDerived().TransformDecl(E->getLocStart(), |
| 5632 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5633 | if (!Constructor) |
| 5634 | return SemaRef.ExprError(); |
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 | bool ArgumentChanged = false; |
| 5637 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5638 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5639 | ArgEnd = E->arg_end(); |
| 5640 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5641 | if (getDerived().DropCallArgument(*Arg)) { |
| 5642 | ArgumentChanged = true; |
| 5643 | break; |
| 5644 | } |
| 5645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5646 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5647 | if (TransArg.isInvalid()) |
| 5648 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5650 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5651 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5652 | } |
| 5653 | |
| 5654 | if (!getDerived().AlwaysRebuild() && |
| 5655 | T == E->getType() && |
| 5656 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5657 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5658 | // Mark the constructor as referenced. |
| 5659 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5660 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5661 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5662 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5663 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5664 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5665 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5666 | move_arg(Args)); |
| 5667 | } |
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 | /// \brief Transform a C++ temporary-binding expression. |
| 5670 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5671 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5672 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5673 | template<typename Derived> |
| 5674 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5675 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5676 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5679 | /// \brief Transform a C++ reference-binding expression. |
| 5680 | /// |
| 5681 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5682 | /// transform the subexpression and return that. |
| 5683 | template<typename Derived> |
| 5684 | Sema::OwningExprResult |
| 5685 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5686 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5687 | } |
| 5688 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5690 | /// be destroyed after the expression is evaluated. |
| 5691 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5692 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5693 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5694 | template<typename Derived> |
| 5695 | Sema::OwningExprResult |
| 5696 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5697 | CXXExprWithTemporaries *E) { |
| 5698 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5699 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5700 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5701 | template<typename Derived> |
| 5702 | Sema::OwningExprResult |
| 5703 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5704 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5705 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5706 | QualType T = getDerived().TransformType(E->getType()); |
| 5707 | if (T.isNull()) |
| 5708 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5710 | CXXConstructorDecl *Constructor |
| 5711 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5712 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5713 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5714 | if (!Constructor) |
| 5715 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5716 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5717 | bool ArgumentChanged = false; |
| 5718 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5719 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5720 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5721 | ArgEnd = E->arg_end(); |
| 5722 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5723 | if (getDerived().DropCallArgument(*Arg)) { |
| 5724 | ArgumentChanged = true; |
| 5725 | break; |
| 5726 | } |
| 5727 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5728 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5729 | if (TransArg.isInvalid()) |
| 5730 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5732 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5733 | Args.push_back((Expr *)TransArg.release()); |
| 5734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5736 | if (!getDerived().AlwaysRebuild() && |
| 5737 | T == E->getType() && |
| 5738 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5739 | !ArgumentChanged) { |
| 5740 | // FIXME: Instantiation-specific |
| 5741 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5742 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5743 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5744 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5745 | // FIXME: Bogus location information |
| 5746 | SourceLocation CommaLoc; |
| 5747 | if (Args.size() > 1) { |
| 5748 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5749 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5750 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5751 | } |
| 5752 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5753 | T, |
| 5754 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5755 | move_arg(Args), |
| 5756 | &CommaLoc, |
| 5757 | E->getLocEnd()); |
| 5758 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5759 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5760 | template<typename Derived> |
| 5761 | Sema::OwningExprResult |
| 5762 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5763 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5764 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5765 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5766 | if (T.isNull()) |
| 5767 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5769 | bool ArgumentChanged = false; |
| 5770 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5771 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5772 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5773 | ArgEnd = E->arg_end(); |
| 5774 | Arg != ArgEnd; ++Arg) { |
| 5775 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5776 | if (TransArg.isInvalid()) |
| 5777 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5778 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5779 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5780 | FakeCommaLocs.push_back( |
| 5781 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5782 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5783 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5784 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5785 | if (!getDerived().AlwaysRebuild() && |
| 5786 | T == E->getTypeAsWritten() && |
| 5787 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5788 | return SemaRef.Owned(E->Retain()); |
| 5789 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5790 | // FIXME: we're faking the locations of the commas |
| 5791 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5792 | T, |
| 5793 | E->getLParenLoc(), |
| 5794 | move_arg(Args), |
| 5795 | FakeCommaLocs.data(), |
| 5796 | E->getRParenLoc()); |
| 5797 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5798 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5799 | template<typename Derived> |
| 5800 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5801 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5802 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5803 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5804 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5805 | Expr *OldBase; |
| 5806 | QualType BaseType; |
| 5807 | QualType ObjectType; |
| 5808 | if (!E->isImplicitAccess()) { |
| 5809 | OldBase = E->getBase(); |
| 5810 | Base = getDerived().TransformExpr(OldBase); |
| 5811 | if (Base.isInvalid()) |
| 5812 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5813 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5814 | // Start the member reference and compute the object's type. |
| 5815 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5816 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5817 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5818 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5819 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5820 | ObjectTy, |
| 5821 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5822 | if (Base.isInvalid()) |
| 5823 | return SemaRef.ExprError(); |
| 5824 | |
| 5825 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5826 | BaseType = ((Expr*) Base.get())->getType(); |
| 5827 | } else { |
| 5828 | OldBase = 0; |
| 5829 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5830 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5832 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5833 | // Transform the first part of the nested-name-specifier that qualifies |
| 5834 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5835 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5836 | = getDerived().TransformFirstQualifierInScope( |
| 5837 | E->getFirstQualifierFoundInScope(), |
| 5838 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5839 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5840 | NestedNameSpecifier *Qualifier = 0; |
| 5841 | if (E->getQualifier()) { |
| 5842 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5843 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5844 | ObjectType, |
| 5845 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5846 | if (!Qualifier) |
| 5847 | return SemaRef.ExprError(); |
| 5848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5849 | |
| 5850 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5851 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5852 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5853 | if (!Name) |
| 5854 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5855 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5856 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5857 | // This is a reference to a member without an explicitly-specified |
| 5858 | // template argument list. Optimize for this common case. |
| 5859 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5860 | Base.get() == OldBase && |
| 5861 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5862 | Qualifier == E->getQualifier() && |
| 5863 | Name == E->getMember() && |
| 5864 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5865 | return SemaRef.Owned(E->Retain()); |
| 5866 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5867 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5868 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5869 | E->isArrow(), |
| 5870 | E->getOperatorLoc(), |
| 5871 | Qualifier, |
| 5872 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5873 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5874 | Name, |
| 5875 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5876 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5879 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5880 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5881 | TemplateArgumentLoc Loc; |
| 5882 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5883 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5884 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5885 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5886 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5887 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5888 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5889 | E->isArrow(), |
| 5890 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5891 | Qualifier, |
| 5892 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5893 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5894 | Name, |
| 5895 | E->getMemberLoc(), |
| 5896 | &TransArgs); |
| 5897 | } |
| 5898 | |
| 5899 | template<typename Derived> |
| 5900 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5901 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5902 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5903 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5904 | QualType BaseType; |
| 5905 | if (!Old->isImplicitAccess()) { |
| 5906 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5907 | if (Base.isInvalid()) |
| 5908 | return SemaRef.ExprError(); |
| 5909 | BaseType = ((Expr*) Base.get())->getType(); |
| 5910 | } else { |
| 5911 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5912 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5913 | |
| 5914 | NestedNameSpecifier *Qualifier = 0; |
| 5915 | if (Old->getQualifier()) { |
| 5916 | Qualifier |
| 5917 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5918 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5919 | if (Qualifier == 0) |
| 5920 | return SemaRef.ExprError(); |
| 5921 | } |
| 5922 | |
| 5923 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5924 | Sema::LookupOrdinaryName); |
| 5925 | |
| 5926 | // Transform all the decls. |
| 5927 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5928 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5929 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5930 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5931 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5932 | if (!InstD) { |
| 5933 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5934 | // This can happen because of dependent hiding. |
| 5935 | if (isa<UsingShadowDecl>(*I)) |
| 5936 | continue; |
| 5937 | else |
| 5938 | return SemaRef.ExprError(); |
| 5939 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5940 | |
| 5941 | // Expand using declarations. |
| 5942 | if (isa<UsingDecl>(InstD)) { |
| 5943 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5944 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5945 | E = UD->shadow_end(); I != E; ++I) |
| 5946 | R.addDecl(*I); |
| 5947 | continue; |
| 5948 | } |
| 5949 | |
| 5950 | R.addDecl(InstD); |
| 5951 | } |
| 5952 | |
| 5953 | R.resolveKind(); |
| 5954 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5955 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 5956 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5957 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5958 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5959 | Old->getMemberLoc(), |
| 5960 | Old->getNamingClass())); |
| 5961 | if (!NamingClass) |
| 5962 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5963 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5964 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5965 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5966 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5967 | TemplateArgumentListInfo TransArgs; |
| 5968 | if (Old->hasExplicitTemplateArgs()) { |
| 5969 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5970 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5971 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5972 | TemplateArgumentLoc Loc; |
| 5973 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5974 | Loc)) |
| 5975 | return SemaRef.ExprError(); |
| 5976 | TransArgs.addArgument(Loc); |
| 5977 | } |
| 5978 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5979 | |
| 5980 | // FIXME: to do this check properly, we will need to preserve the |
| 5981 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5982 | // base (and therefore couldn't do the check) and a |
| 5983 | // nested-name-qualifier (and therefore could do the lookup). |
| 5984 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5985 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5986 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5987 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5988 | Old->getOperatorLoc(), |
| 5989 | Old->isArrow(), |
| 5990 | Qualifier, |
| 5991 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5992 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5993 | R, |
| 5994 | (Old->hasExplicitTemplateArgs() |
| 5995 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5996 | } |
| 5997 | |
| 5998 | template<typename Derived> |
| 5999 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6000 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6001 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6004 | template<typename Derived> |
| 6005 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6006 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6007 | TypeSourceInfo *EncodedTypeInfo |
| 6008 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 6009 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6010 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6012 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6013 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6014 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6015 | |
| 6016 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6017 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6018 | E->getRParenLoc()); |
| 6019 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6021 | template<typename Derived> |
| 6022 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6023 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6024 | // Transform arguments. |
| 6025 | bool ArgChanged = false; |
| 6026 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 6027 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 6028 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 6029 | if (Arg.isInvalid()) |
| 6030 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6031 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6032 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 6033 | Args.push_back(Arg.takeAs<Expr>()); |
| 6034 | } |
| 6035 | |
| 6036 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 6037 | // Class message: transform the receiver type. |
| 6038 | TypeSourceInfo *ReceiverTypeInfo |
| 6039 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 6040 | if (!ReceiverTypeInfo) |
| 6041 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6042 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6043 | // If nothing changed, just retain the existing message send. |
| 6044 | if (!getDerived().AlwaysRebuild() && |
| 6045 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 6046 | return SemaRef.Owned(E->Retain()); |
| 6047 | |
| 6048 | // Build a new class message send. |
| 6049 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 6050 | E->getSelector(), |
| 6051 | E->getMethodDecl(), |
| 6052 | E->getLeftLoc(), |
| 6053 | move_arg(Args), |
| 6054 | E->getRightLoc()); |
| 6055 | } |
| 6056 | |
| 6057 | // Instance message: transform the receiver |
| 6058 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 6059 | "Only class and instance messages may be instantiated"); |
| 6060 | OwningExprResult Receiver |
| 6061 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 6062 | if (Receiver.isInvalid()) |
| 6063 | return SemaRef.ExprError(); |
| 6064 | |
| 6065 | // If nothing changed, just retain the existing message send. |
| 6066 | if (!getDerived().AlwaysRebuild() && |
| 6067 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 6068 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6069 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6070 | // Build a new instance message send. |
| 6071 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 6072 | E->getSelector(), |
| 6073 | E->getMethodDecl(), |
| 6074 | E->getLeftLoc(), |
| 6075 | move_arg(Args), |
| 6076 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6079 | template<typename Derived> |
| 6080 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6081 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6085 | template<typename Derived> |
| 6086 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6087 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6088 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6089 | } |
| 6090 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6091 | template<typename Derived> |
| 6092 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6093 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6094 | // Transform the base expression. |
| 6095 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6096 | if (Base.isInvalid()) |
| 6097 | return SemaRef.ExprError(); |
| 6098 | |
| 6099 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6100 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6101 | // If nothing changed, just retain the existing expression. |
| 6102 | if (!getDerived().AlwaysRebuild() && |
| 6103 | Base.get() == E->getBase()) |
| 6104 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6105 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6106 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6107 | E->getLocation(), |
| 6108 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6111 | template<typename Derived> |
| 6112 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6113 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6114 | // Transform the base expression. |
| 6115 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6116 | if (Base.isInvalid()) |
| 6117 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6118 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6119 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6120 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6121 | // If nothing changed, just retain the existing expression. |
| 6122 | if (!getDerived().AlwaysRebuild() && |
| 6123 | Base.get() == E->getBase()) |
| 6124 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6125 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6126 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6127 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6128 | } |
| 6129 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6130 | template<typename Derived> |
| 6131 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6132 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6133 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6134 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6135 | // dependent parts. Just retain the existing declaration. |
| 6136 | if (E->getInterfaceDecl()) |
| 6137 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6138 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6139 | // Transform the base expression. |
| 6140 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6141 | if (Base.isInvalid()) |
| 6142 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6143 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6144 | // We don't need to transform the getters/setters; they will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6145 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6146 | // If nothing changed, just retain the existing expression. |
| 6147 | if (!getDerived().AlwaysRebuild() && |
| 6148 | Base.get() == E->getBase()) |
| 6149 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6150 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6151 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6152 | E->getGetterMethod(), |
| 6153 | E->getType(), |
| 6154 | E->getSetterMethod(), |
| 6155 | E->getLocation(), |
| 6156 | move(Base)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6158 | } |
| 6159 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6160 | template<typename Derived> |
| 6161 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6162 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6163 | // Can never occur in a dependent context. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6164 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6165 | } |
| 6166 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6167 | template<typename Derived> |
| 6168 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6169 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6170 | // Transform the base expression. |
| 6171 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6172 | if (Base.isInvalid()) |
| 6173 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6174 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6175 | // If nothing changed, just retain the existing expression. |
| 6176 | if (!getDerived().AlwaysRebuild() && |
| 6177 | Base.get() == E->getBase()) |
| 6178 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6179 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6180 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6181 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6182 | } |
| 6183 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6184 | template<typename Derived> |
| 6185 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6186 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6187 | bool ArgumentChanged = false; |
| 6188 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6189 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6190 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6191 | if (SubExpr.isInvalid()) |
| 6192 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6194 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6195 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6196 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6197 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6198 | if (!getDerived().AlwaysRebuild() && |
| 6199 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6200 | return SemaRef.Owned(E->Retain()); |
| 6201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6202 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6203 | move_arg(SubExprs), |
| 6204 | E->getRParenLoc()); |
| 6205 | } |
| 6206 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6207 | template<typename Derived> |
| 6208 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6209 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6210 | SourceLocation CaretLoc(E->getExprLoc()); |
| 6211 | |
| 6212 | SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0); |
| 6213 | BlockScopeInfo *CurBlock = SemaRef.getCurBlock(); |
| 6214 | CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic()); |
| 6215 | llvm::SmallVector<ParmVarDecl*, 4> Params; |
| 6216 | llvm::SmallVector<QualType, 4> ParamTypes; |
| 6217 | |
| 6218 | // Parameter substitution. |
| 6219 | const BlockDecl *BD = E->getBlockDecl(); |
| 6220 | for (BlockDecl::param_const_iterator P = BD->param_begin(), |
| 6221 | EN = BD->param_end(); P != EN; ++P) { |
| 6222 | ParmVarDecl *OldParm = (*P); |
| 6223 | ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 6224 | QualType NewType = NewParm->getType(); |
| 6225 | Params.push_back(NewParm); |
| 6226 | ParamTypes.push_back(NewParm->getType()); |
| 6227 | } |
| 6228 | |
| 6229 | const FunctionType *BExprFunctionType = E->getFunctionType(); |
| 6230 | QualType BExprResultType = BExprFunctionType->getResultType(); |
| 6231 | if (!BExprResultType.isNull()) { |
| 6232 | if (!BExprResultType->isDependentType()) |
| 6233 | CurBlock->ReturnType = BExprResultType; |
| 6234 | else if (BExprResultType != SemaRef.Context.DependentTy) |
| 6235 | CurBlock->ReturnType = getDerived().TransformType(BExprResultType); |
| 6236 | } |
| 6237 | |
| 6238 | // Transform the body |
| 6239 | OwningStmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 6240 | if (Body.isInvalid()) |
| 6241 | return SemaRef.ExprError(); |
| 6242 | // Set the parameters on the block decl. |
| 6243 | if (!Params.empty()) |
| 6244 | CurBlock->TheDecl->setParams(Params.data(), Params.size()); |
| 6245 | |
| 6246 | QualType FunctionType = getDerived().RebuildFunctionProtoType( |
| 6247 | CurBlock->ReturnType, |
| 6248 | ParamTypes.data(), |
| 6249 | ParamTypes.size(), |
| 6250 | BD->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6251 | 0, |
| 6252 | BExprFunctionType->getExtInfo()); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6253 | |
| 6254 | CurBlock->FunctionType = FunctionType; |
| 6255 | return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6258 | template<typename Derived> |
| 6259 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6260 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6261 | NestedNameSpecifier *Qualifier = 0; |
| 6262 | |
| 6263 | ValueDecl *ND |
| 6264 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6265 | E->getDecl())); |
| 6266 | if (!ND) |
| 6267 | return SemaRef.ExprError(); |
| 6268 | |
| 6269 | if (!getDerived().AlwaysRebuild() && |
| 6270 | ND == E->getDecl()) { |
| 6271 | // Mark it referenced in the new context regardless. |
| 6272 | // FIXME: this is a bit instantiation-specific. |
| 6273 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 6274 | |
| 6275 | return SemaRef.Owned(E->Retain()); |
| 6276 | } |
| 6277 | |
| 6278 | return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(), |
| 6279 | ND, E->getLocation(), 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6282 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6283 | // Type reconstruction |
| 6284 | //===----------------------------------------------------------------------===// |
| 6285 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6286 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6287 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6288 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6289 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6290 | getDerived().getBaseEntity()); |
| 6291 | } |
| 6292 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6293 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6294 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6295 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6296 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6297 | getDerived().getBaseEntity()); |
| 6298 | } |
| 6299 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6300 | template<typename Derived> |
| 6301 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6302 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6303 | bool WrittenAsLValue, |
| 6304 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6305 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6306 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6310 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6311 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6312 | QualType ClassType, |
| 6313 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6314 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6315 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6319 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6320 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6321 | ArrayType::ArraySizeModifier SizeMod, |
| 6322 | const llvm::APInt *Size, |
| 6323 | Expr *SizeExpr, |
| 6324 | unsigned IndexTypeQuals, |
| 6325 | SourceRange BracketsRange) { |
| 6326 | if (SizeExpr || !Size) |
| 6327 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6328 | IndexTypeQuals, BracketsRange, |
| 6329 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6330 | |
| 6331 | QualType Types[] = { |
| 6332 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6333 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6334 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6335 | }; |
| 6336 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6337 | QualType SizeType; |
| 6338 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6339 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6340 | SizeType = Types[I]; |
| 6341 | break; |
| 6342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6343 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6344 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6345 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6346 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6347 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6350 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6351 | QualType |
| 6352 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6353 | ArrayType::ArraySizeModifier SizeMod, |
| 6354 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6355 | unsigned IndexTypeQuals, |
| 6356 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6357 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6358 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6362 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6363 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6364 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6365 | unsigned IndexTypeQuals, |
| 6366 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6367 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6368 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6370 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6371 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6372 | QualType |
| 6373 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6374 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6375 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6376 | unsigned IndexTypeQuals, |
| 6377 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6378 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6379 | SizeExpr.takeAs<Expr>(), |
| 6380 | IndexTypeQuals, BracketsRange); |
| 6381 | } |
| 6382 | |
| 6383 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6384 | QualType |
| 6385 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6386 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6387 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6388 | unsigned IndexTypeQuals, |
| 6389 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6390 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6391 | SizeExpr.takeAs<Expr>(), |
| 6392 | IndexTypeQuals, BracketsRange); |
| 6393 | } |
| 6394 | |
| 6395 | template<typename Derived> |
| 6396 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6397 | unsigned NumElements, |
| 6398 | VectorType::AltiVecSpecific AltiVecSpec) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6399 | // FIXME: semantic checking! |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6400 | return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6402 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6403 | template<typename Derived> |
| 6404 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6405 | unsigned NumElements, |
| 6406 | SourceLocation AttributeLoc) { |
| 6407 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6408 | NumElements, true); |
| 6409 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6410 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6411 | AttributeLoc); |
| 6412 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6413 | AttributeLoc); |
| 6414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6415 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6416 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6417 | QualType |
| 6418 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6419 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6420 | SourceLocation AttributeLoc) { |
| 6421 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6422 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6423 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6424 | template<typename Derived> |
| 6425 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6426 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6427 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6428 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6429 | unsigned Quals, |
| 6430 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6431 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6432 | Quals, |
| 6433 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6434 | getDerived().getBaseEntity(), |
| 6435 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6437 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6438 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6439 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6440 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6441 | } |
| 6442 | |
| 6443 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6444 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6445 | assert(D && "no decl found"); |
| 6446 | if (D->isInvalidDecl()) return QualType(); |
| 6447 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6448 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6449 | TypeDecl *Ty; |
| 6450 | if (isa<UsingDecl>(D)) { |
| 6451 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6452 | assert(Using->isTypeName() && |
| 6453 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6454 | |
| 6455 | // A valid resolved using typename decl points to exactly one type decl. |
| 6456 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6457 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6458 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6459 | } else { |
| 6460 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6461 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6462 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6463 | } |
| 6464 | |
| 6465 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6466 | } |
| 6467 | |
| 6468 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6470 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6471 | } |
| 6472 | |
| 6473 | template<typename Derived> |
| 6474 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6475 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6476 | } |
| 6477 | |
| 6478 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6479 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6480 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6481 | } |
| 6482 | |
| 6483 | template<typename Derived> |
| 6484 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6485 | TemplateName Template, |
| 6486 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6487 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6488 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6489 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6490 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6491 | template<typename Derived> |
| 6492 | NestedNameSpecifier * |
| 6493 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6494 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6495 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6496 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6497 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6498 | CXXScopeSpec SS; |
| 6499 | // FIXME: The source location information is all wrong. |
| 6500 | SS.setRange(Range); |
| 6501 | SS.setScopeRep(Prefix); |
| 6502 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6503 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6504 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6505 | ObjectType, |
| 6506 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6507 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | template<typename Derived> |
| 6511 | NestedNameSpecifier * |
| 6512 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6513 | SourceRange Range, |
| 6514 | NamespaceDecl *NS) { |
| 6515 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6516 | } |
| 6517 | |
| 6518 | template<typename Derived> |
| 6519 | NestedNameSpecifier * |
| 6520 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6521 | SourceRange Range, |
| 6522 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6523 | QualType T) { |
| 6524 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6525 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6526 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6527 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6528 | T.getTypePtr()); |
| 6529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6530 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6531 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6532 | return 0; |
| 6533 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6534 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6535 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6536 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6537 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6538 | bool TemplateKW, |
| 6539 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6540 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6541 | Template); |
| 6542 | } |
| 6543 | |
| 6544 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6545 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6546 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6547 | const IdentifierInfo &II, |
| 6548 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6549 | CXXScopeSpec SS; |
| 6550 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6551 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6552 | UnqualifiedId Name; |
| 6553 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6554 | Sema::TemplateTy Template; |
| 6555 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 6556 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6557 | SS, |
| 6558 | Name, |
| 6559 | ObjectType.getAsOpaquePtr(), |
| 6560 | /*EnteringContext=*/false, |
| 6561 | Template); |
| 6562 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6564 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6565 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6566 | TemplateName |
| 6567 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6568 | OverloadedOperatorKind Operator, |
| 6569 | QualType ObjectType) { |
| 6570 | CXXScopeSpec SS; |
| 6571 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6572 | SS.setScopeRep(Qualifier); |
| 6573 | UnqualifiedId Name; |
| 6574 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6575 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6576 | Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6577 | Sema::TemplateTy Template; |
| 6578 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6579 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6580 | SS, |
| 6581 | Name, |
| 6582 | ObjectType.getAsOpaquePtr(), |
| 6583 | /*EnteringContext=*/false, |
| 6584 | Template); |
| 6585 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6586 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6587 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6588 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6589 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6590 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6591 | SourceLocation OpLoc, |
| 6592 | ExprArg Callee, |
| 6593 | ExprArg First, |
| 6594 | ExprArg Second) { |
| 6595 | Expr *FirstExpr = (Expr *)First.get(); |
| 6596 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6597 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6598 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6600 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6601 | if (Op == OO_Subscript) { |
| 6602 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6603 | !SecondExpr->getType()->isOverloadableType()) |
| 6604 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6605 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6606 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6607 | } else if (Op == OO_Arrow) { |
| 6608 | // -> is never a builtin operation. |
| 6609 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6610 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6611 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6612 | // The argument is not of overloadable type, so try to create a |
| 6613 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6614 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6615 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6616 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6617 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6618 | } |
| 6619 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6620 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6621 | !SecondExpr->getType()->isOverloadableType()) { |
| 6622 | // Neither of the arguments is an overloadable type, so try to |
| 6623 | // create a built-in binary operation. |
| 6624 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6625 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6626 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6627 | if (Result.isInvalid()) |
| 6628 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6629 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6630 | First.release(); |
| 6631 | Second.release(); |
| 6632 | return move(Result); |
| 6633 | } |
| 6634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6635 | |
| 6636 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6637 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6638 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6639 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6640 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6641 | assert(ULE->requiresADL()); |
| 6642 | |
| 6643 | // FIXME: Do we have to check |
| 6644 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6645 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6646 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6647 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6650 | // Add any functions found via argument-dependent lookup. |
| 6651 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6652 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6654 | // Create the overloaded operator invocation for unary operators. |
| 6655 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6656 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6657 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6658 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6659 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6661 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6662 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6663 | OpLoc, |
| 6664 | move(First), |
| 6665 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6666 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6667 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6668 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6669 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6670 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6671 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6672 | if (Result.isInvalid()) |
| 6673 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6675 | First.release(); |
| 6676 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6677 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6679 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6680 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6681 | Sema::OwningExprResult |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6682 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6683 | SourceLocation OperatorLoc, |
| 6684 | bool isArrow, |
| 6685 | NestedNameSpecifier *Qualifier, |
| 6686 | SourceRange QualifierRange, |
| 6687 | TypeSourceInfo *ScopeType, |
| 6688 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6689 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6690 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6691 | CXXScopeSpec SS; |
| 6692 | if (Qualifier) { |
| 6693 | SS.setRange(QualifierRange); |
| 6694 | SS.setScopeRep(Qualifier); |
| 6695 | } |
| 6696 | |
| 6697 | Expr *BaseE = (Expr *)Base.get(); |
| 6698 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6699 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6700 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6701 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6702 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6703 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6704 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6705 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6706 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6707 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6708 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6709 | /*FIXME?*/true); |
| 6710 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6711 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6712 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6713 | DeclarationName Name |
| 6714 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6715 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6716 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6717 | // FIXME: the ScopeType should be tacked onto SS. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6718 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6719 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6720 | OperatorLoc, isArrow, |
| 6721 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6722 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6723 | /*TemplateArgs*/ 0); |
| 6724 | } |
| 6725 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6726 | } // end namespace clang |
| 6727 | |
| 6728 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |