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 | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 347 | #define ABSTRACT(Stmt) |
| 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, |
| 445 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 447 | /// \brief Build a new extended vector type given the element type and |
| 448 | /// number of elements. |
| 449 | /// |
| 450 | /// By default, performs semantic analysis when building the vector type. |
| 451 | /// Subclasses may override this routine to provide different behavior. |
| 452 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 453 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
| 455 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// given the element type and number of elements. |
| 457 | /// |
| 458 | /// By default, performs semantic analysis when building the vector type. |
| 459 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 461 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new function type. |
| 465 | /// |
| 466 | /// By default, performs semantic analysis when building the function type. |
| 467 | /// Subclasses may override this routine to provide different behavior. |
| 468 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 470 | unsigned NumParamTypes, |
| 471 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 473 | /// \brief Build a new unprototyped function type. |
| 474 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 475 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 476 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 477 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 478 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 479 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Build a new typedef type. |
| 481 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 482 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 483 | } |
| 484 | |
| 485 | /// \brief Build a new class/struct/union type. |
| 486 | QualType RebuildRecordType(RecordDecl *Record) { |
| 487 | return SemaRef.Context.getTypeDeclType(Record); |
| 488 | } |
| 489 | |
| 490 | /// \brief Build a new Enum type. |
| 491 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 492 | return SemaRef.Context.getTypeDeclType(Enum); |
| 493 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 494 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 496 | /// |
| 497 | /// By default, performs semantic analysis when building the typeof type. |
| 498 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 499 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 500 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 502 | /// |
| 503 | /// By default, builds a new TypeOfType with the given underlying type. |
| 504 | QualType RebuildTypeOfType(QualType Underlying); |
| 505 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, performs semantic analysis when building the decltype type. |
| 509 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 510 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// \brief Build a new template specialization type. |
| 513 | /// |
| 514 | /// By default, performs semantic analysis when building the template |
| 515 | /// specialization type. Subclasses may override this routine to provide |
| 516 | /// different behavior. |
| 517 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 518 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 519 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | /// \brief Build a new qualified name type. |
| 522 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 523 | /// By default, builds a new ElaboratedType type from the keyword, |
| 524 | /// the nested-name-specifier and the named type. |
| 525 | /// Subclasses may override this routine to provide different behavior. |
| 526 | QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword, |
| 527 | NestedNameSpecifier *NNS, QualType Named) { |
| 528 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | |
| 531 | /// \brief Build a new typename type that refers to a template-id. |
| 532 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 533 | /// By default, builds a new DependentNameType type from the |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 534 | /// nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 537 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 538 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 539 | if (NNS->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 540 | // If the name is still dependent, just build a new dependent name type. |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 541 | CXXScopeSpec SS; |
| 542 | SS.setScopeRep(NNS); |
| 543 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 544 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 545 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 546 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 547 | |
| 548 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 550 | |
| 551 | /// \brief Build a new typename type that refers to an identifier. |
| 552 | /// |
| 553 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 555 | /// different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 556 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 557 | NestedNameSpecifier *NNS, |
| 558 | const IdentifierInfo *Id, |
| 559 | SourceRange SR) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 560 | CXXScopeSpec SS; |
| 561 | SS.setScopeRep(NNS); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 562 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 563 | if (NNS->isDependent()) { |
| 564 | // If the name is still dependent, just build a new dependent name type. |
| 565 | if (!SemaRef.computeDeclContext(SS)) |
| 566 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 567 | } |
| 568 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 569 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
| 570 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR); |
| 571 | |
| 572 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 573 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 574 | // We had a dependent elaborated-type-specifier that as been transformed |
| 575 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 576 | // referring to. |
| 577 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 578 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 579 | if (!DC) |
| 580 | return QualType(); |
| 581 | |
| 582 | TagDecl *Tag = 0; |
| 583 | SemaRef.LookupQualifiedName(Result, DC); |
| 584 | switch (Result.getResultKind()) { |
| 585 | case LookupResult::NotFound: |
| 586 | case LookupResult::NotFoundInCurrentInstantiation: |
| 587 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 588 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 589 | case LookupResult::Found: |
| 590 | Tag = Result.getAsSingle<TagDecl>(); |
| 591 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 592 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 593 | case LookupResult::FoundOverloaded: |
| 594 | case LookupResult::FoundUnresolvedValue: |
| 595 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 596 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 597 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 598 | case LookupResult::Ambiguous: |
| 599 | // Let the LookupResult structure handle ambiguities. |
| 600 | return QualType(); |
| 601 | } |
| 602 | |
| 603 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 604 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 605 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 606 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 607 | return QualType(); |
| 608 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 610 | // FIXME: Terrible location information |
| 611 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 612 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 613 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 614 | return QualType(); |
| 615 | } |
| 616 | |
| 617 | // Build the elaborated-type-specifier type. |
| 618 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 619 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 620 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 622 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 623 | /// identifier that names the next step in the nested-name-specifier. |
| 624 | /// |
| 625 | /// By default, performs semantic analysis when building the new |
| 626 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 627 | /// different behavior. |
| 628 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 629 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 630 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 631 | QualType ObjectType, |
| 632 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 633 | |
| 634 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 635 | /// namespace named in the next step in the nested-name-specifier. |
| 636 | /// |
| 637 | /// By default, performs semantic analysis when building the new |
| 638 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 639 | /// different behavior. |
| 640 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 641 | SourceRange Range, |
| 642 | NamespaceDecl *NS); |
| 643 | |
| 644 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 645 | /// type named in the next step in the nested-name-specifier. |
| 646 | /// |
| 647 | /// By default, performs semantic analysis when building the new |
| 648 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 649 | /// different behavior. |
| 650 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 651 | SourceRange Range, |
| 652 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 653 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 654 | |
| 655 | /// \brief Build a new template name given a nested name specifier, a flag |
| 656 | /// indicating whether the "template" keyword was provided, and the template |
| 657 | /// that the template name refers to. |
| 658 | /// |
| 659 | /// By default, builds the new template name directly. Subclasses may override |
| 660 | /// this routine to provide different behavior. |
| 661 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 662 | bool TemplateKW, |
| 663 | TemplateDecl *Template); |
| 664 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 665 | /// \brief Build a new template name given a nested name specifier and the |
| 666 | /// name that is referred to as a template. |
| 667 | /// |
| 668 | /// By default, performs semantic analysis to determine whether the name can |
| 669 | /// be resolved to a specific template, then builds the appropriate kind of |
| 670 | /// template name. Subclasses may override this routine to provide different |
| 671 | /// behavior. |
| 672 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 673 | const IdentifierInfo &II, |
| 674 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 675 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 676 | /// \brief Build a new template name given a nested name specifier and the |
| 677 | /// overloaded operator name that is referred to as a template. |
| 678 | /// |
| 679 | /// By default, performs semantic analysis to determine whether the name can |
| 680 | /// be resolved to a specific template, then builds the appropriate kind of |
| 681 | /// template name. Subclasses may override this routine to provide different |
| 682 | /// behavior. |
| 683 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 684 | OverloadedOperatorKind Operator, |
| 685 | QualType ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 687 | /// \brief Build a new compound statement. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis to build the new statement. |
| 690 | /// Subclasses may override this routine to provide different behavior. |
| 691 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 692 | MultiStmtArg Statements, |
| 693 | SourceLocation RBraceLoc, |
| 694 | bool IsStmtExpr) { |
| 695 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 696 | IsStmtExpr); |
| 697 | } |
| 698 | |
| 699 | /// \brief Build a new case statement. |
| 700 | /// |
| 701 | /// By default, performs semantic analysis to build the new statement. |
| 702 | /// Subclasses may override this routine to provide different behavior. |
| 703 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 704 | ExprArg LHS, |
| 705 | SourceLocation EllipsisLoc, |
| 706 | ExprArg RHS, |
| 707 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 709 | ColonLoc); |
| 710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 712 | /// \brief Attach the body to a new case statement. |
| 713 | /// |
| 714 | /// By default, performs semantic analysis to build the new statement. |
| 715 | /// Subclasses may override this routine to provide different behavior. |
| 716 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 717 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 718 | return move(S); |
| 719 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 721 | /// \brief Build a new default statement. |
| 722 | /// |
| 723 | /// By default, performs semantic analysis to build the new statement. |
| 724 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | SourceLocation ColonLoc, |
| 727 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 729 | /*CurScope=*/0); |
| 730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 732 | /// \brief Build a new label statement. |
| 733 | /// |
| 734 | /// By default, performs semantic analysis to build the new statement. |
| 735 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 737 | IdentifierInfo *Id, |
| 738 | SourceLocation ColonLoc, |
| 739 | StmtArg SubStmt) { |
| 740 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 741 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 743 | /// \brief Build a new "if" statement. |
| 744 | /// |
| 745 | /// By default, performs semantic analysis to build the new statement. |
| 746 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 747 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 748 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 749 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 750 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 751 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 754 | /// \brief Start building a new switch statement. |
| 755 | /// |
| 756 | /// By default, performs semantic analysis to build the new statement. |
| 757 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 758 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 759 | Sema::ExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 760 | VarDecl *CondVar) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 761 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 762 | DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 763 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 765 | /// \brief Attach the body to the switch statement. |
| 766 | /// |
| 767 | /// By default, performs semantic analysis to build the new statement. |
| 768 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 770 | StmtArg Switch, StmtArg Body) { |
| 771 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 772 | move(Body)); |
| 773 | } |
| 774 | |
| 775 | /// \brief Build a new while statement. |
| 776 | /// |
| 777 | /// By default, performs semantic analysis to build the new statement. |
| 778 | /// Subclasses may override this routine to provide different behavior. |
| 779 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 780 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 781 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 782 | StmtArg Body) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 783 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 784 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 785 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 787 | /// \brief Build a new do-while statement. |
| 788 | /// |
| 789 | /// By default, performs semantic analysis to build the new statement. |
| 790 | /// Subclasses may override this routine to provide different behavior. |
| 791 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 792 | SourceLocation WhileLoc, |
| 793 | SourceLocation LParenLoc, |
| 794 | ExprArg Cond, |
| 795 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 796 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 797 | move(Cond), RParenLoc); |
| 798 | } |
| 799 | |
| 800 | /// \brief Build a new for statement. |
| 801 | /// |
| 802 | /// By default, performs semantic analysis to build the new statement. |
| 803 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 805 | SourceLocation LParenLoc, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 806 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 807 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 808 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 809 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 810 | DeclPtrTy::make(CondVar), |
| 811 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 813 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 814 | /// \brief Build a new goto statement. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis to build the new statement. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
| 818 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 819 | SourceLocation LabelLoc, |
| 820 | LabelStmt *Label) { |
| 821 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 822 | } |
| 823 | |
| 824 | /// \brief Build a new indirect goto statement. |
| 825 | /// |
| 826 | /// By default, performs semantic analysis to build the new statement. |
| 827 | /// Subclasses may override this routine to provide different behavior. |
| 828 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 829 | SourceLocation StarLoc, |
| 830 | ExprArg Target) { |
| 831 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 834 | /// \brief Build a new return statement. |
| 835 | /// |
| 836 | /// By default, performs semantic analysis to build the new statement. |
| 837 | /// Subclasses may override this routine to provide different behavior. |
| 838 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 839 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 841 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 844 | /// \brief Build a new declaration statement. |
| 845 | /// |
| 846 | /// By default, performs semantic analysis to build the new statement. |
| 847 | /// Subclasses may override this routine to provide different behavior. |
| 848 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 849 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 850 | SourceLocation EndLoc) { |
| 851 | return getSema().Owned( |
| 852 | new (getSema().Context) DeclStmt( |
| 853 | DeclGroupRef::Create(getSema().Context, |
| 854 | Decls, NumDecls), |
| 855 | StartLoc, EndLoc)); |
| 856 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 858 | /// \brief Build a new inline asm statement. |
| 859 | /// |
| 860 | /// By default, performs semantic analysis to build the new statement. |
| 861 | /// Subclasses may override this routine to provide different behavior. |
| 862 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 863 | bool IsSimple, |
| 864 | bool IsVolatile, |
| 865 | unsigned NumOutputs, |
| 866 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 867 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 868 | MultiExprArg Constraints, |
| 869 | MultiExprArg Exprs, |
| 870 | ExprArg AsmString, |
| 871 | MultiExprArg Clobbers, |
| 872 | SourceLocation RParenLoc, |
| 873 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 874 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 875 | NumInputs, Names, move(Constraints), |
| 876 | move(Exprs), move(AsmString), move(Clobbers), |
| 877 | RParenLoc, MSAsm); |
| 878 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 879 | |
| 880 | /// \brief Build a new Objective-C @try statement. |
| 881 | /// |
| 882 | /// By default, performs semantic analysis to build the new statement. |
| 883 | /// Subclasses may override this routine to provide different behavior. |
| 884 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 885 | StmtArg TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 886 | MultiStmtArg CatchStmts, |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 887 | StmtArg Finally) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 888 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 889 | move(Finally)); |
| 890 | } |
| 891 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 892 | /// \brief Rebuild an Objective-C exception declaration. |
| 893 | /// |
| 894 | /// By default, performs semantic analysis to build the new declaration. |
| 895 | /// Subclasses may override this routine to provide different behavior. |
| 896 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 897 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 898 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 899 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 900 | ExceptionDecl->getLocation()); |
| 901 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 902 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 903 | /// \brief Build a new Objective-C @catch statement. |
| 904 | /// |
| 905 | /// By default, performs semantic analysis to build the new statement. |
| 906 | /// Subclasses may override this routine to provide different behavior. |
| 907 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 908 | SourceLocation RParenLoc, |
| 909 | VarDecl *Var, |
| 910 | StmtArg Body) { |
| 911 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 912 | Sema::DeclPtrTy::make(Var), |
| 913 | move(Body)); |
| 914 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 915 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 916 | /// \brief Build a new Objective-C @finally statement. |
| 917 | /// |
| 918 | /// By default, performs semantic analysis to build the new statement. |
| 919 | /// Subclasses may override this routine to provide different behavior. |
| 920 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 921 | StmtArg Body) { |
| 922 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 923 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 925 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 926 | /// |
| 927 | /// By default, performs semantic analysis to build the new statement. |
| 928 | /// Subclasses may override this routine to provide different behavior. |
| 929 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 930 | ExprArg Operand) { |
| 931 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 932 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 933 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 934 | /// \brief Build a new Objective-C @synchronized statement. |
| 935 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 936 | /// By default, performs semantic analysis to build the new statement. |
| 937 | /// Subclasses may override this routine to provide different behavior. |
| 938 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 939 | ExprArg Object, |
| 940 | StmtArg Body) { |
| 941 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 942 | move(Body)); |
| 943 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 944 | |
| 945 | /// \brief Build a new Objective-C fast enumeration statement. |
| 946 | /// |
| 947 | /// By default, performs semantic analysis to build the new statement. |
| 948 | /// Subclasses may override this routine to provide different behavior. |
| 949 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 950 | SourceLocation LParenLoc, |
| 951 | StmtArg Element, |
| 952 | ExprArg Collection, |
| 953 | SourceLocation RParenLoc, |
| 954 | StmtArg Body) { |
| 955 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 956 | move(Element), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 957 | move(Collection), |
| 958 | RParenLoc, |
| 959 | move(Body)); |
| 960 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 961 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 962 | /// \brief Build a new C++ exception declaration. |
| 963 | /// |
| 964 | /// By default, performs semantic analysis to build the new decaration. |
| 965 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 967 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 968 | IdentifierInfo *Name, |
| 969 | SourceLocation Loc, |
| 970 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 972 | TypeRange); |
| 973 | } |
| 974 | |
| 975 | /// \brief Build a new C++ catch statement. |
| 976 | /// |
| 977 | /// By default, performs semantic analysis to build the new statement. |
| 978 | /// Subclasses may override this routine to provide different behavior. |
| 979 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 980 | VarDecl *ExceptionDecl, |
| 981 | StmtArg Handler) { |
| 982 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 984 | Handler.takeAs<Stmt>())); |
| 985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 987 | /// \brief Build a new C++ try statement. |
| 988 | /// |
| 989 | /// By default, performs semantic analysis to build the new statement. |
| 990 | /// Subclasses may override this routine to provide different behavior. |
| 991 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 992 | StmtArg TryBlock, |
| 993 | MultiStmtArg Handlers) { |
| 994 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 997 | /// \brief Build a new expression that references a declaration. |
| 998 | /// |
| 999 | /// By default, performs semantic analysis to build the new expression. |
| 1000 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1001 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1002 | LookupResult &R, |
| 1003 | bool RequiresADL) { |
| 1004 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | /// \brief Build a new expression that references a declaration. |
| 1009 | /// |
| 1010 | /// By default, performs semantic analysis to build the new expression. |
| 1011 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1012 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1013 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1014 | ValueDecl *VD, SourceLocation Loc, |
| 1015 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1016 | CXXScopeSpec SS; |
| 1017 | SS.setScopeRep(Qualifier); |
| 1018 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1019 | |
| 1020 | // FIXME: loses template args. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1021 | |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1022 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1027 | /// By default, performs semantic analysis to build the new expression. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
| 1029 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1030 | SourceLocation RParen) { |
| 1031 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1032 | } |
| 1033 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1034 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1035 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1036 | /// By default, performs semantic analysis to build the new expression. |
| 1037 | /// Subclasses may override this routine to provide different behavior. |
| 1038 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1039 | SourceLocation OperatorLoc, |
| 1040 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1041 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1042 | SourceRange QualifierRange, |
| 1043 | TypeSourceInfo *ScopeType, |
| 1044 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1045 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1046 | PseudoDestructorTypeStorage Destroyed); |
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 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | /// By default, performs semantic analysis to build the new expression. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
| 1052 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1053 | UnaryOperator::Opcode Opc, |
| 1054 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1055 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1056 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1058 | /// \brief Build a new builtin offsetof expression. |
| 1059 | /// |
| 1060 | /// By default, performs semantic analysis to build the new expression. |
| 1061 | /// Subclasses may override this routine to provide different behavior. |
| 1062 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1063 | TypeSourceInfo *Type, |
| 1064 | Action::OffsetOfComponent *Components, |
| 1065 | unsigned NumComponents, |
| 1066 | SourceLocation RParenLoc) { |
| 1067 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1068 | NumComponents, RParenLoc); |
| 1069 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1070 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1071 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1072 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1073 | /// By default, performs semantic analysis to build the new expression. |
| 1074 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1075 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1076 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1077 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1078 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1082 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1084 | /// By default, performs semantic analysis to build the new expression. |
| 1085 | /// Subclasses may override this routine to provide different behavior. |
| 1086 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1087 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1089 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1090 | OpLoc, isSizeOf, R); |
| 1091 | if (Result.isInvalid()) |
| 1092 | return getSema().ExprError(); |
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 | SubExpr.release(); |
| 1095 | return move(Result); |
| 1096 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1099 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | /// By default, performs semantic analysis to build the new expression. |
| 1101 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1103 | SourceLocation LBracketLoc, |
| 1104 | ExprArg RHS, |
| 1105 | SourceLocation RBracketLoc) { |
| 1106 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | RBracketLoc); |
| 1109 | } |
| 1110 | |
| 1111 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1113 | /// By default, performs semantic analysis to build the new expression. |
| 1114 | /// Subclasses may override this routine to provide different behavior. |
| 1115 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1116 | MultiExprArg Args, |
| 1117 | SourceLocation *CommaLocs, |
| 1118 | SourceLocation RParenLoc) { |
| 1119 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1120 | move(Args), CommaLocs, RParenLoc); |
| 1121 | } |
| 1122 | |
| 1123 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | /// By default, performs semantic analysis to build the new expression. |
| 1126 | /// Subclasses may override this routine to provide different behavior. |
| 1127 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1129 | NestedNameSpecifier *Qualifier, |
| 1130 | SourceRange QualifierRange, |
| 1131 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1132 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1133 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1134 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1135 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1136 | if (!Member->getDeclName()) { |
| 1137 | // We have a reference to an unnamed field. |
| 1138 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1140 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1141 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1142 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1143 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1144 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1146 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1147 | Member, MemberLoc, |
| 1148 | cast<FieldDecl>(Member)->getType()); |
| 1149 | return getSema().Owned(ME); |
| 1150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1152 | CXXScopeSpec SS; |
| 1153 | if (Qualifier) { |
| 1154 | SS.setRange(QualifierRange); |
| 1155 | SS.setScopeRep(Qualifier); |
| 1156 | } |
| 1157 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1158 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1159 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1160 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1161 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1162 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1163 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1164 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1165 | R.resolveKind(); |
| 1166 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1167 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1168 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1169 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1170 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1173 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1174 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1175 | /// By default, performs semantic analysis to build the new expression. |
| 1176 | /// Subclasses may override this routine to provide different behavior. |
| 1177 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1178 | BinaryOperator::Opcode Opc, |
| 1179 | ExprArg LHS, ExprArg RHS) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1180 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1181 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1186 | /// By default, performs semantic analysis to build the new expression. |
| 1187 | /// Subclasses may override this routine to provide different behavior. |
| 1188 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1189 | SourceLocation QuestionLoc, |
| 1190 | ExprArg LHS, |
| 1191 | SourceLocation ColonLoc, |
| 1192 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | move(LHS), move(RHS)); |
| 1195 | } |
| 1196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1197 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | /// By default, performs semantic analysis to build the new expression. |
| 1200 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1201 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1202 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1203 | SourceLocation RParenLoc, |
| 1204 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1205 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1206 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1207 | } |
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 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1211 | /// By default, performs semantic analysis to build the new expression. |
| 1212 | /// Subclasses may override this routine to provide different behavior. |
| 1213 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1214 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | SourceLocation RParenLoc, |
| 1216 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1217 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1218 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1223 | /// By default, performs semantic analysis to build the new expression. |
| 1224 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | SourceLocation OpLoc, |
| 1227 | SourceLocation AccessorLoc, |
| 1228 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1229 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1230 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1231 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1232 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1233 | OpLoc, /*IsArrow*/ false, |
| 1234 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1235 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1236 | AccessorLoc, |
| 1237 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | /// By default, performs semantic analysis to build the new expression. |
| 1243 | /// Subclasses may override this routine to provide different behavior. |
| 1244 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1245 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1246 | SourceLocation RBraceLoc, |
| 1247 | QualType ResultTy) { |
| 1248 | OwningExprResult Result |
| 1249 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1250 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1251 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1252 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1253 | // Patch in the result type we were given, which may have been computed |
| 1254 | // when the initial InitListExpr was built. |
| 1255 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1256 | ILE->setType(ResultTy); |
| 1257 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1258 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1260 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1261 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1262 | /// By default, performs semantic analysis to build the new expression. |
| 1263 | /// Subclasses may override this routine to provide different behavior. |
| 1264 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1265 | MultiExprArg ArrayExprs, |
| 1266 | SourceLocation EqualOrColonLoc, |
| 1267 | bool GNUSyntax, |
| 1268 | ExprArg Init) { |
| 1269 | OwningExprResult Result |
| 1270 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1271 | move(Init)); |
| 1272 | if (Result.isInvalid()) |
| 1273 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1274 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1275 | ArrayExprs.release(); |
| 1276 | return move(Result); |
| 1277 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1278 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1280 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1281 | /// By default, builds the implicit value initialization without performing |
| 1282 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1283 | /// different behavior. |
| 1284 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1285 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1288 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1289 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1290 | /// By default, performs semantic analysis to build the new expression. |
| 1291 | /// Subclasses may override this routine to provide different behavior. |
| 1292 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1293 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | RParenLoc); |
| 1296 | } |
| 1297 | |
| 1298 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | /// By default, performs semantic analysis to build the new expression. |
| 1301 | /// Subclasses may override this routine to provide different behavior. |
| 1302 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1303 | MultiExprArg SubExprs, |
| 1304 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1305 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1306 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | /// |
| 1311 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | /// rather than attempting to map the label statement itself. |
| 1313 | /// Subclasses may override this routine to provide different behavior. |
| 1314 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1315 | SourceLocation LabelLoc, |
| 1316 | LabelStmt *Label) { |
| 1317 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1318 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1319 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1320 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1321 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1322 | /// By default, performs semantic analysis to build the new expression. |
| 1323 | /// Subclasses may override this routine to provide different behavior. |
| 1324 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1325 | StmtArg SubStmt, |
| 1326 | SourceLocation RParenLoc) { |
| 1327 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1328 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1329 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1331 | /// |
| 1332 | /// By default, performs semantic analysis to build the new expression. |
| 1333 | /// Subclasses may override this routine to provide different behavior. |
| 1334 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1335 | QualType T1, QualType T2, |
| 1336 | SourceLocation RParenLoc) { |
| 1337 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1338 | T1.getAsOpaquePtr(), |
| 1339 | T2.getAsOpaquePtr(), |
| 1340 | RParenLoc); |
| 1341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | /// \brief Build a new __builtin_choose_expr expression. |
| 1344 | /// |
| 1345 | /// By default, performs semantic analysis to build the new expression. |
| 1346 | /// Subclasses may override this routine to provide different behavior. |
| 1347 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1348 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1349 | SourceLocation RParenLoc) { |
| 1350 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1351 | move(Cond), move(LHS), move(RHS), |
| 1352 | 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 overloaded operator call expression. |
| 1356 | /// |
| 1357 | /// By default, performs semantic analysis to build the new expression. |
| 1358 | /// The semantic analysis provides the behavior of template instantiation, |
| 1359 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1360 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1361 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1362 | /// provide different behavior. |
| 1363 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1364 | SourceLocation OpLoc, |
| 1365 | ExprArg Callee, |
| 1366 | ExprArg First, |
| 1367 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1368 | |
| 1369 | /// \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] | 1370 | /// reinterpret_cast. |
| 1371 | /// |
| 1372 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1374 | /// Subclasses may override this routine to provide different behavior. |
| 1375 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1376 | Stmt::StmtClass Class, |
| 1377 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1378 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | SourceLocation RAngleLoc, |
| 1380 | SourceLocation LParenLoc, |
| 1381 | ExprArg SubExpr, |
| 1382 | SourceLocation RParenLoc) { |
| 1383 | switch (Class) { |
| 1384 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1385 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1386 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1387 | move(SubExpr), RParenLoc); |
| 1388 | |
| 1389 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1390 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1391 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1394 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1395 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | RAngleLoc, LParenLoc, |
| 1397 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1398 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1401 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | default: |
| 1406 | assert(false && "Invalid C++ named cast"); |
| 1407 | break; |
| 1408 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | return getSema().ExprError(); |
| 1411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | /// \brief Build a new C++ static_cast expression. |
| 1414 | /// |
| 1415 | /// By default, performs semantic analysis to build the new expression. |
| 1416 | /// Subclasses may override this routine to provide different behavior. |
| 1417 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1418 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1419 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1420 | SourceLocation RAngleLoc, |
| 1421 | SourceLocation LParenLoc, |
| 1422 | ExprArg SubExpr, |
| 1423 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1424 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1425 | TInfo, move(SubExpr), |
| 1426 | SourceRange(LAngleLoc, RAngleLoc), |
| 1427 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /// \brief Build a new C++ dynamic_cast expression. |
| 1431 | /// |
| 1432 | /// By default, performs semantic analysis to build the new expression. |
| 1433 | /// Subclasses may override this routine to provide different behavior. |
| 1434 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1435 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1436 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1437 | SourceLocation RAngleLoc, |
| 1438 | SourceLocation LParenLoc, |
| 1439 | ExprArg SubExpr, |
| 1440 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1441 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1442 | TInfo, move(SubExpr), |
| 1443 | SourceRange(LAngleLoc, RAngleLoc), |
| 1444 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1448 | /// |
| 1449 | /// By default, performs semantic analysis to build the new expression. |
| 1450 | /// Subclasses may override this routine to provide different behavior. |
| 1451 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1452 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1453 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1454 | SourceLocation RAngleLoc, |
| 1455 | SourceLocation LParenLoc, |
| 1456 | ExprArg SubExpr, |
| 1457 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1458 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1459 | TInfo, move(SubExpr), |
| 1460 | SourceRange(LAngleLoc, RAngleLoc), |
| 1461 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | /// \brief Build a new C++ const_cast expression. |
| 1465 | /// |
| 1466 | /// By default, performs semantic analysis to build the new expression. |
| 1467 | /// Subclasses may override this routine to provide different behavior. |
| 1468 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1469 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1470 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | SourceLocation RAngleLoc, |
| 1472 | SourceLocation LParenLoc, |
| 1473 | ExprArg SubExpr, |
| 1474 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1475 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1476 | TInfo, move(SubExpr), |
| 1477 | SourceRange(LAngleLoc, RAngleLoc), |
| 1478 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1480 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1481 | /// \brief Build a new C++ functional-style cast expression. |
| 1482 | /// |
| 1483 | /// By default, performs semantic analysis to build the new expression. |
| 1484 | /// Subclasses may override this routine to provide different behavior. |
| 1485 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1486 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1487 | SourceLocation LParenLoc, |
| 1488 | ExprArg SubExpr, |
| 1489 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1490 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1491 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1492 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1493 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1494 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1496 | RParenLoc); |
| 1497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1499 | /// \brief Build a new C++ typeid(type) expression. |
| 1500 | /// |
| 1501 | /// By default, performs semantic analysis to build the new expression. |
| 1502 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1503 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1504 | SourceLocation TypeidLoc, |
| 1505 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1507 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1508 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1509 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | /// \brief Build a new C++ typeid(expr) expression. |
| 1512 | /// |
| 1513 | /// By default, performs semantic analysis to build the new expression. |
| 1514 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1515 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1516 | SourceLocation TypeidLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | ExprArg Operand, |
| 1518 | SourceLocation RParenLoc) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1519 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1520 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1523 | /// \brief Build a new C++ "this" expression. |
| 1524 | /// |
| 1525 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1528 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1529 | QualType ThisType, |
| 1530 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1532 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1533 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | /// \brief Build a new C++ throw expression. |
| 1537 | /// |
| 1538 | /// By default, performs semantic analysis to build the new expression. |
| 1539 | /// Subclasses may override this routine to provide different behavior. |
| 1540 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1541 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1542 | } |
| 1543 | |
| 1544 | /// \brief Build a new C++ default-argument expression. |
| 1545 | /// |
| 1546 | /// By default, builds a new default-argument expression, which does not |
| 1547 | /// require any semantic analysis. Subclasses may override this routine to |
| 1548 | /// provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1549 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1550 | ParmVarDecl *Param) { |
| 1551 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1552 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | /// \brief Build a new C++ zero-initialization expression. |
| 1556 | /// |
| 1557 | /// By default, performs semantic analysis to build the new expression. |
| 1558 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1559 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | SourceLocation LParenLoc, |
| 1561 | QualType T, |
| 1562 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1564 | T.getAsOpaquePtr(), LParenLoc, |
| 1565 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1566 | 0, RParenLoc); |
| 1567 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | /// \brief Build a new C++ "new" expression. |
| 1570 | /// |
| 1571 | /// By default, performs semantic analysis to build the new expression. |
| 1572 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | bool UseGlobal, |
| 1575 | SourceLocation PlacementLParen, |
| 1576 | MultiExprArg PlacementArgs, |
| 1577 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | QualType AllocType, |
| 1580 | SourceLocation TypeLoc, |
| 1581 | SourceRange TypeRange, |
| 1582 | ExprArg ArraySize, |
| 1583 | SourceLocation ConstructorLParen, |
| 1584 | MultiExprArg ConstructorArgs, |
| 1585 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1587 | PlacementLParen, |
| 1588 | move(PlacementArgs), |
| 1589 | PlacementRParen, |
| 1590 | ParenTypeId, |
| 1591 | AllocType, |
| 1592 | TypeLoc, |
| 1593 | TypeRange, |
| 1594 | move(ArraySize), |
| 1595 | ConstructorLParen, |
| 1596 | move(ConstructorArgs), |
| 1597 | ConstructorRParen); |
| 1598 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | /// \brief Build a new C++ "delete" expression. |
| 1601 | /// |
| 1602 | /// By default, performs semantic analysis to build the new expression. |
| 1603 | /// Subclasses may override this routine to provide different behavior. |
| 1604 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1605 | bool IsGlobalDelete, |
| 1606 | bool IsArrayForm, |
| 1607 | ExprArg Operand) { |
| 1608 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1609 | move(Operand)); |
| 1610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | /// \brief Build a new unary type trait expression. |
| 1613 | /// |
| 1614 | /// By default, performs semantic analysis to build the new expression. |
| 1615 | /// Subclasses may override this routine to provide different behavior. |
| 1616 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1617 | SourceLocation StartLoc, |
| 1618 | SourceLocation LParenLoc, |
| 1619 | QualType T, |
| 1620 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1621 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | T.getAsOpaquePtr(), RParenLoc); |
| 1623 | } |
| 1624 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | /// expression. |
| 1627 | /// |
| 1628 | /// By default, performs semantic analysis to build the new expression. |
| 1629 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1630 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1631 | SourceRange QualifierRange, |
| 1632 | DeclarationName Name, |
| 1633 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1634 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | CXXScopeSpec SS; |
| 1636 | SS.setRange(QualifierRange); |
| 1637 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1638 | |
| 1639 | if (TemplateArgs) |
| 1640 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1641 | *TemplateArgs); |
| 1642 | |
| 1643 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | /// \brief Build a new template-id expression. |
| 1647 | /// |
| 1648 | /// By default, performs semantic analysis to build the new expression. |
| 1649 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1650 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1651 | LookupResult &R, |
| 1652 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1653 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1654 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | /// \brief Build a new object-construction expression. |
| 1658 | /// |
| 1659 | /// By default, performs semantic analysis to build the new expression. |
| 1660 | /// Subclasses may override this routine to provide different behavior. |
| 1661 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1662 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1663 | CXXConstructorDecl *Constructor, |
| 1664 | bool IsElidable, |
| 1665 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1666 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1667 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1668 | ConvertedArgs)) |
| 1669 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1670 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1671 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1672 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | /// \brief Build a new object-construction expression. |
| 1676 | /// |
| 1677 | /// By default, performs semantic analysis to build the new expression. |
| 1678 | /// Subclasses may override this routine to provide different behavior. |
| 1679 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1680 | QualType T, |
| 1681 | SourceLocation LParenLoc, |
| 1682 | MultiExprArg Args, |
| 1683 | SourceLocation *Commas, |
| 1684 | SourceLocation RParenLoc) { |
| 1685 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1686 | T.getAsOpaquePtr(), |
| 1687 | LParenLoc, |
| 1688 | move(Args), |
| 1689 | Commas, |
| 1690 | RParenLoc); |
| 1691 | } |
| 1692 | |
| 1693 | /// \brief Build a new object-construction expression. |
| 1694 | /// |
| 1695 | /// By default, performs semantic analysis to build the new expression. |
| 1696 | /// Subclasses may override this routine to provide different behavior. |
| 1697 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1698 | QualType T, |
| 1699 | SourceLocation LParenLoc, |
| 1700 | MultiExprArg Args, |
| 1701 | SourceLocation *Commas, |
| 1702 | SourceLocation RParenLoc) { |
| 1703 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1704 | /*FIXME*/LParenLoc), |
| 1705 | T.getAsOpaquePtr(), |
| 1706 | LParenLoc, |
| 1707 | move(Args), |
| 1708 | Commas, |
| 1709 | RParenLoc); |
| 1710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1712 | /// \brief Build a new member reference expression. |
| 1713 | /// |
| 1714 | /// By default, performs semantic analysis to build the new expression. |
| 1715 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1716 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1717 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | bool IsArrow, |
| 1719 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1720 | NestedNameSpecifier *Qualifier, |
| 1721 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1722 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1723 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1724 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1725 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1726 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1727 | SS.setRange(QualifierRange); |
| 1728 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1730 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1731 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1732 | SS, FirstQualifierInScope, |
| 1733 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1736 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1737 | /// |
| 1738 | /// By default, performs semantic analysis to build the new expression. |
| 1739 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1740 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1741 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1742 | SourceLocation OperatorLoc, |
| 1743 | bool IsArrow, |
| 1744 | NestedNameSpecifier *Qualifier, |
| 1745 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1746 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1747 | LookupResult &R, |
| 1748 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1749 | CXXScopeSpec SS; |
| 1750 | SS.setRange(QualifierRange); |
| 1751 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1753 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1754 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1755 | SS, FirstQualifierInScope, |
| 1756 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1757 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1759 | /// \brief Build a new Objective-C @encode expression. |
| 1760 | /// |
| 1761 | /// By default, performs semantic analysis to build the new expression. |
| 1762 | /// Subclasses may override this routine to provide different behavior. |
| 1763 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1764 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1765 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1766 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1767 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1770 | /// \brief Build a new Objective-C class message. |
| 1771 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1772 | Selector Sel, |
| 1773 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1774 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1775 | MultiExprArg Args, |
| 1776 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1777 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1778 | ReceiverTypeInfo->getType(), |
| 1779 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1780 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1781 | move(Args)); |
| 1782 | } |
| 1783 | |
| 1784 | /// \brief Build a new Objective-C instance message. |
| 1785 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1786 | Selector Sel, |
| 1787 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1788 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1789 | MultiExprArg Args, |
| 1790 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1791 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1792 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1793 | ReceiverType, |
| 1794 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1795 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1796 | move(Args)); |
| 1797 | } |
| 1798 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1799 | /// \brief Build a new Objective-C ivar reference expression. |
| 1800 | /// |
| 1801 | /// By default, performs semantic analysis to build the new expression. |
| 1802 | /// Subclasses may override this routine to provide different behavior. |
| 1803 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1804 | SourceLocation IvarLoc, |
| 1805 | bool IsArrow, bool IsFreeIvar) { |
| 1806 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1807 | CXXScopeSpec SS; |
| 1808 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1809 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1810 | Sema::LookupMemberName); |
| 1811 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1812 | /*FIME:*/IvarLoc, |
| 1813 | SS, DeclPtrTy()); |
| 1814 | if (Result.isInvalid()) |
| 1815 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1816 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1817 | if (Result.get()) |
| 1818 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1819 | |
| 1820 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1821 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1822 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1823 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1824 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1825 | /*TemplateArgs=*/0); |
| 1826 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1827 | |
| 1828 | /// \brief Build a new Objective-C property reference expression. |
| 1829 | /// |
| 1830 | /// By default, performs semantic analysis to build the new expression. |
| 1831 | /// Subclasses may override this routine to provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1832 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1833 | ObjCPropertyDecl *Property, |
| 1834 | SourceLocation PropertyLoc) { |
| 1835 | CXXScopeSpec SS; |
| 1836 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1837 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1838 | Sema::LookupMemberName); |
| 1839 | bool IsArrow = false; |
| 1840 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1841 | /*FIME:*/PropertyLoc, |
| 1842 | SS, DeclPtrTy()); |
| 1843 | if (Result.isInvalid()) |
| 1844 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1846 | if (Result.get()) |
| 1847 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1848 | |
| 1849 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1850 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1851 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1852 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1853 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1854 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1855 | /*TemplateArgs=*/0); |
| 1856 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1857 | |
| 1858 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1859 | /// expression. |
| 1860 | /// |
| 1861 | /// By default, performs semantic analysis to build the new expression. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1862 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1863 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1864 | ObjCMethodDecl *Getter, |
| 1865 | QualType T, |
| 1866 | ObjCMethodDecl *Setter, |
| 1867 | SourceLocation NameLoc, |
| 1868 | ExprArg Base) { |
| 1869 | // Since these expressions can only be value-dependent, we do not need to |
| 1870 | // perform semantic analysis again. |
| 1871 | return getSema().Owned( |
| 1872 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1873 | Setter, |
| 1874 | NameLoc, |
| 1875 | Base.takeAs<Expr>())); |
| 1876 | } |
| 1877 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1878 | /// \brief Build a new Objective-C "isa" expression. |
| 1879 | /// |
| 1880 | /// By default, performs semantic analysis to build the new expression. |
| 1881 | /// Subclasses may override this routine to provide different behavior. |
| 1882 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1883 | bool IsArrow) { |
| 1884 | CXXScopeSpec SS; |
| 1885 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1886 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1887 | Sema::LookupMemberName); |
| 1888 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1889 | /*FIME:*/IsaLoc, |
| 1890 | SS, DeclPtrTy()); |
| 1891 | if (Result.isInvalid()) |
| 1892 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1893 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1894 | if (Result.get()) |
| 1895 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1896 | |
| 1897 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1898 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1899 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1900 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1901 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1902 | /*TemplateArgs=*/0); |
| 1903 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1904 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1905 | /// \brief Build a new shuffle vector 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 RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1910 | MultiExprArg SubExprs, |
| 1911 | SourceLocation RParenLoc) { |
| 1912 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1913 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1914 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1915 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1916 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1917 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1919 | // Build a reference to the __builtin_shufflevector builtin |
| 1920 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1921 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1922 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1923 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1924 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1925 | |
| 1926 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1927 | unsigned NumSubExprs = SubExprs.size(); |
| 1928 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1929 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1930 | Subs, NumSubExprs, |
| 1931 | Builtin->getResultType(), |
| 1932 | RParenLoc); |
| 1933 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1934 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1935 | // Type-check the __builtin_shufflevector expression. |
| 1936 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1937 | if (Result.isInvalid()) |
| 1938 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1939 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1940 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1941 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1942 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1943 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1944 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1945 | template<typename Derived> |
| 1946 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1947 | if (!S) |
| 1948 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1950 | switch (S->getStmtClass()) { |
| 1951 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1952 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1953 | // Transform individual statement nodes |
| 1954 | #define STMT(Node, Parent) \ |
| 1955 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1956 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1957 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1958 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1959 | // Transform expressions by calling TransformExpr. |
| 1960 | #define STMT(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1961 | #define ABSTRACT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1962 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1963 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1964 | { |
| 1965 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1966 | if (E.isInvalid()) |
| 1967 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1968 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1969 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1970 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1973 | return SemaRef.Owned(S->Retain()); |
| 1974 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1975 | |
| 1976 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1977 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1978 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1979 | if (!E) |
| 1980 | return SemaRef.Owned(E); |
| 1981 | |
| 1982 | switch (E->getStmtClass()) { |
| 1983 | case Stmt::NoStmtClass: break; |
| 1984 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1985 | #define ABSTRACT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1986 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1987 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1988 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1991 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1995 | NestedNameSpecifier * |
| 1996 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1997 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1998 | QualType ObjectType, |
| 1999 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2000 | if (!NNS) |
| 2001 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2002 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2003 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2004 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2005 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2006 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2007 | ObjectType, |
| 2008 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2009 | if (!Prefix) |
| 2010 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2011 | |
| 2012 | // 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] | 2013 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2014 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2015 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2018 | switch (NNS->getKind()) { |
| 2019 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2021 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2022 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2023 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2024 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | |
| 2026 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2027 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2028 | ObjectType, |
| 2029 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2030 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2031 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2032 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2033 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2034 | getDerived().TransformDecl(Range.getBegin(), |
| 2035 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2036 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2037 | Prefix == NNS->getPrefix() && |
| 2038 | NS == NNS->getAsNamespace()) |
| 2039 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2041 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2042 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2043 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2044 | case NestedNameSpecifier::Global: |
| 2045 | // There is no meaningful transformation that one could perform on the |
| 2046 | // global scope. |
| 2047 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2049 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2050 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2051 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2052 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2053 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2054 | if (T.isNull()) |
| 2055 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2056 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2057 | if (!getDerived().AlwaysRebuild() && |
| 2058 | Prefix == NNS->getPrefix() && |
| 2059 | T == QualType(NNS->getAsType(), 0)) |
| 2060 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2061 | |
| 2062 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2063 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2064 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2065 | } |
| 2066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2068 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2074 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2075 | SourceLocation Loc, |
| 2076 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2077 | if (!Name) |
| 2078 | return Name; |
| 2079 | |
| 2080 | switch (Name.getNameKind()) { |
| 2081 | case DeclarationName::Identifier: |
| 2082 | case DeclarationName::ObjCZeroArgSelector: |
| 2083 | case DeclarationName::ObjCOneArgSelector: |
| 2084 | case DeclarationName::ObjCMultiArgSelector: |
| 2085 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2086 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2087 | case DeclarationName::CXXUsingDirective: |
| 2088 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2090 | case DeclarationName::CXXConstructorName: |
| 2091 | case DeclarationName::CXXDestructorName: |
| 2092 | case DeclarationName::CXXConversionFunctionName: { |
| 2093 | TemporaryBase Rebase(*this, Loc, Name); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2094 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2095 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2096 | if (T.isNull()) |
| 2097 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2098 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2099 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2100 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2101 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2102 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2105 | return DeclarationName(); |
| 2106 | } |
| 2107 | |
| 2108 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2109 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2110 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2111 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2112 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2113 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2114 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2115 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2116 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2117 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2118 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2119 | if (!NNS) |
| 2120 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2121 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2122 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2123 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2124 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2125 | if (!TransTemplate) |
| 2126 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2127 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2128 | if (!getDerived().AlwaysRebuild() && |
| 2129 | NNS == QTN->getQualifier() && |
| 2130 | TransTemplate == Template) |
| 2131 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2132 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2133 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2134 | TransTemplate); |
| 2135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2136 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2137 | // These should be getting filtered out before they make it into the AST. |
| 2138 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2140 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2141 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2142 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2143 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2144 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2145 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2146 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2147 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2148 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2149 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2150 | NNS == DTN->getQualifier() && |
| 2151 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2152 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2153 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2154 | if (DTN->isIdentifier()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2155 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2156 | ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2157 | |
| 2158 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2159 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2161 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2162 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2163 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2164 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2165 | if (!TransTemplate) |
| 2166 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2167 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2168 | if (!getDerived().AlwaysRebuild() && |
| 2169 | TransTemplate == Template) |
| 2170 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2172 | return TemplateName(TransTemplate); |
| 2173 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2174 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2175 | // These should be getting filtered out before they reach the AST. |
| 2176 | assert(false && "overloaded function decl survived to here"); |
| 2177 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2181 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2182 | const TemplateArgument &Arg, |
| 2183 | TemplateArgumentLoc &Output) { |
| 2184 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2185 | switch (Arg.getKind()) { |
| 2186 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2187 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2188 | break; |
| 2189 | |
| 2190 | case TemplateArgument::Type: |
| 2191 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2192 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2193 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2196 | case TemplateArgument::Template: |
| 2197 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2198 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2199 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2200 | case TemplateArgument::Expression: |
| 2201 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2202 | break; |
| 2203 | |
| 2204 | case TemplateArgument::Declaration: |
| 2205 | case TemplateArgument::Integral: |
| 2206 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2207 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2208 | break; |
| 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | template<typename Derived> |
| 2213 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2214 | const TemplateArgumentLoc &Input, |
| 2215 | TemplateArgumentLoc &Output) { |
| 2216 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2217 | switch (Arg.getKind()) { |
| 2218 | case TemplateArgument::Null: |
| 2219 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2220 | Output = Input; |
| 2221 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2223 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2224 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2225 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2226 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2227 | |
| 2228 | DI = getDerived().TransformType(DI); |
| 2229 | if (!DI) return true; |
| 2230 | |
| 2231 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2232 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2233 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2234 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2235 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2236 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2237 | DeclarationName Name; |
| 2238 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2239 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2240 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2241 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2242 | if (!D) return true; |
| 2243 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2244 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2245 | if (SourceExpr) { |
| 2246 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2247 | Action::Unevaluated); |
| 2248 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2249 | if (E.isInvalid()) |
| 2250 | SourceExpr = NULL; |
| 2251 | else { |
| 2252 | SourceExpr = E.takeAs<Expr>(); |
| 2253 | SourceExpr->Retain(); |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2258 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2261 | case TemplateArgument::Template: { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2262 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2263 | TemplateName Template |
| 2264 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2265 | if (Template.isNull()) |
| 2266 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2267 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2268 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2269 | Input.getTemplateQualifierRange(), |
| 2270 | Input.getTemplateNameLoc()); |
| 2271 | return false; |
| 2272 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2273 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2274 | case TemplateArgument::Expression: { |
| 2275 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2277 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2279 | Expr *InputExpr = Input.getSourceExpression(); |
| 2280 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2281 | |
| 2282 | Sema::OwningExprResult E |
| 2283 | = getDerived().TransformExpr(InputExpr); |
| 2284 | if (E.isInvalid()) return true; |
| 2285 | |
| 2286 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2287 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2288 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2289 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2290 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2291 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2292 | case TemplateArgument::Pack: { |
| 2293 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2294 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2295 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2296 | AEnd = Arg.pack_end(); |
| 2297 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2299 | // FIXME: preserve source information here when we start |
| 2300 | // caring about parameter packs. |
| 2301 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2302 | TemplateArgumentLoc InputArg; |
| 2303 | TemplateArgumentLoc OutputArg; |
| 2304 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2305 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2306 | return true; |
| 2307 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2308 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2309 | } |
| 2310 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2311 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2312 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2313 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2314 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2315 | } |
| 2316 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2317 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2318 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2319 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2322 | //===----------------------------------------------------------------------===// |
| 2323 | // Type transformation |
| 2324 | //===----------------------------------------------------------------------===// |
| 2325 | |
| 2326 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2327 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2328 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2329 | if (getDerived().AlreadyTransformed(T)) |
| 2330 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2331 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2332 | // Temporary workaround. All of these transformations should |
| 2333 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2334 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2335 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2336 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2337 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2338 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2339 | if (!NewDI) |
| 2340 | return QualType(); |
| 2341 | |
| 2342 | return NewDI->getType(); |
| 2343 | } |
| 2344 | |
| 2345 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2346 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2347 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2348 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2349 | return DI; |
| 2350 | |
| 2351 | TypeLocBuilder TLB; |
| 2352 | |
| 2353 | TypeLoc TL = DI->getTypeLoc(); |
| 2354 | TLB.reserve(TL.getFullDataSize()); |
| 2355 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2356 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2357 | if (Result.isNull()) |
| 2358 | return 0; |
| 2359 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2360 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | template<typename Derived> |
| 2364 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2365 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2366 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2367 | switch (T.getTypeLocClass()) { |
| 2368 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2369 | #define TYPELOC(CLASS, PARENT) \ |
| 2370 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2371 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2372 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2373 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2374 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2375 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2376 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2377 | return QualType(); |
| 2378 | } |
| 2379 | |
| 2380 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2381 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2382 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2383 | /// types). This is the right thing for template instantiation, but |
| 2384 | /// probably not for other clients. |
| 2385 | template<typename Derived> |
| 2386 | QualType |
| 2387 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2388 | QualifiedTypeLoc T, |
| 2389 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2390 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2391 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2392 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2393 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2394 | if (Result.isNull()) |
| 2395 | return QualType(); |
| 2396 | |
| 2397 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2398 | // FIXME: this is the right thing for template instantiation, but |
| 2399 | // probably not for other clients. |
| 2400 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2401 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2402 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2403 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2404 | |
| 2405 | TLB.push<QualifiedTypeLoc>(Result); |
| 2406 | |
| 2407 | // No location information to preserve. |
| 2408 | |
| 2409 | return Result; |
| 2410 | } |
| 2411 | |
| 2412 | template <class TyLoc> static inline |
| 2413 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2414 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2415 | NewT.setNameLoc(T.getNameLoc()); |
| 2416 | return T.getType(); |
| 2417 | } |
| 2418 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2419 | template<typename Derived> |
| 2420 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2421 | BuiltinTypeLoc T, |
| 2422 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2423 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2424 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2425 | if (T.needsExtraLocalData()) |
| 2426 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2427 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2428 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2429 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2430 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2431 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2432 | ComplexTypeLoc T, |
| 2433 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2434 | // FIXME: recurse? |
| 2435 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2437 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2438 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2439 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2440 | PointerTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2441 | QualType ObjectType) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2442 | QualType PointeeType |
| 2443 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2444 | if (PointeeType.isNull()) |
| 2445 | return QualType(); |
| 2446 | |
| 2447 | QualType Result = TL.getType(); |
John McCall | 01f21ad | 2010-05-13 08:39:13 +0000 | [diff] [blame] | 2448 | if (PointeeType->isObjCInterfaceType() || |
| 2449 | PointeeType->isSpecificBuiltinType(BuiltinType::ObjCId)) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2450 | // A dependent pointer type 'T *' has is being transformed such |
| 2451 | // that an Objective-C class type is being replaced for 'T'. The |
| 2452 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2453 | // PointerType. |
John McCall | 01f21ad | 2010-05-13 08:39:13 +0000 | [diff] [blame] | 2454 | ObjCProtocolDecl **Protocols = 0; |
| 2455 | unsigned NumProtocols = 0; |
| 2456 | |
| 2457 | if (const ObjCInterfaceType *IFace |
| 2458 | = PointeeType->getAs<ObjCInterfaceType>()) { |
| 2459 | Protocols = const_cast<ObjCProtocolDecl**>(IFace->qual_begin()); |
| 2460 | NumProtocols = IFace->getNumProtocols(); |
| 2461 | } |
| 2462 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2463 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
John McCall | 01f21ad | 2010-05-13 08:39:13 +0000 | [diff] [blame] | 2464 | Protocols, |
| 2465 | NumProtocols); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2466 | |
| 2467 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2468 | NewT.setStarLoc(TL.getSigilLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2469 | NewT.setHasProtocolsAsWritten(false); |
| 2470 | NewT.setLAngleLoc(SourceLocation()); |
| 2471 | NewT.setRAngleLoc(SourceLocation()); |
| 2472 | NewT.setHasBaseTypeAsWritten(true); |
| 2473 | return Result; |
| 2474 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2475 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2476 | if (getDerived().AlwaysRebuild() || |
| 2477 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2478 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2479 | if (Result.isNull()) |
| 2480 | return QualType(); |
| 2481 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2482 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2483 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2484 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2485 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2487 | |
| 2488 | template<typename Derived> |
| 2489 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2490 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2491 | BlockPointerTypeLoc TL, |
| 2492 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2493 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2494 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2495 | if (PointeeType.isNull()) |
| 2496 | return QualType(); |
| 2497 | |
| 2498 | QualType Result = TL.getType(); |
| 2499 | if (getDerived().AlwaysRebuild() || |
| 2500 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2501 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2502 | TL.getSigilLoc()); |
| 2503 | if (Result.isNull()) |
| 2504 | return QualType(); |
| 2505 | } |
| 2506 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2507 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2508 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2509 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2512 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2513 | /// don't care whether the type itself is an l-value type or an r-value |
| 2514 | /// type; we only care if the type was *written* as an l-value type |
| 2515 | /// or an r-value type. |
| 2516 | template<typename Derived> |
| 2517 | QualType |
| 2518 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2519 | ReferenceTypeLoc TL, |
| 2520 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2521 | const ReferenceType *T = TL.getTypePtr(); |
| 2522 | |
| 2523 | // Note that this works with the pointee-as-written. |
| 2524 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2525 | if (PointeeType.isNull()) |
| 2526 | return QualType(); |
| 2527 | |
| 2528 | QualType Result = TL.getType(); |
| 2529 | if (getDerived().AlwaysRebuild() || |
| 2530 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2531 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2532 | T->isSpelledAsLValue(), |
| 2533 | TL.getSigilLoc()); |
| 2534 | if (Result.isNull()) |
| 2535 | return QualType(); |
| 2536 | } |
| 2537 | |
| 2538 | // r-value references can be rebuilt as l-value references. |
| 2539 | ReferenceTypeLoc NewTL; |
| 2540 | if (isa<LValueReferenceType>(Result)) |
| 2541 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2542 | else |
| 2543 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2544 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2545 | |
| 2546 | return Result; |
| 2547 | } |
| 2548 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2549 | template<typename Derived> |
| 2550 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2551 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2552 | LValueReferenceTypeLoc TL, |
| 2553 | QualType ObjectType) { |
| 2554 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2557 | template<typename Derived> |
| 2558 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2559 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2560 | RValueReferenceTypeLoc TL, |
| 2561 | QualType ObjectType) { |
| 2562 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2564 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2565 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2566 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2567 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2568 | MemberPointerTypeLoc TL, |
| 2569 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2570 | MemberPointerType *T = TL.getTypePtr(); |
| 2571 | |
| 2572 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2573 | if (PointeeType.isNull()) |
| 2574 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2575 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2576 | // TODO: preserve source information for this. |
| 2577 | QualType ClassType |
| 2578 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2579 | if (ClassType.isNull()) |
| 2580 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2582 | QualType Result = TL.getType(); |
| 2583 | if (getDerived().AlwaysRebuild() || |
| 2584 | PointeeType != T->getPointeeType() || |
| 2585 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2586 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2587 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2588 | if (Result.isNull()) |
| 2589 | return QualType(); |
| 2590 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2591 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2592 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2593 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2594 | |
| 2595 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2598 | template<typename Derived> |
| 2599 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2600 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2601 | ConstantArrayTypeLoc TL, |
| 2602 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2603 | ConstantArrayType *T = TL.getTypePtr(); |
| 2604 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2605 | if (ElementType.isNull()) |
| 2606 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2607 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2608 | QualType Result = TL.getType(); |
| 2609 | if (getDerived().AlwaysRebuild() || |
| 2610 | ElementType != T->getElementType()) { |
| 2611 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2612 | T->getSizeModifier(), |
| 2613 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2614 | T->getIndexTypeCVRQualifiers(), |
| 2615 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2616 | if (Result.isNull()) |
| 2617 | return QualType(); |
| 2618 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2619 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2620 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2621 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2622 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2624 | Expr *Size = TL.getSizeExpr(); |
| 2625 | if (Size) { |
| 2626 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2627 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2628 | } |
| 2629 | NewTL.setSizeExpr(Size); |
| 2630 | |
| 2631 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2633 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2634 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2635 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2636 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2637 | IncompleteArrayTypeLoc TL, |
| 2638 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2639 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2640 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2641 | if (ElementType.isNull()) |
| 2642 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2643 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | QualType Result = TL.getType(); |
| 2645 | if (getDerived().AlwaysRebuild() || |
| 2646 | ElementType != T->getElementType()) { |
| 2647 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2648 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2649 | T->getIndexTypeCVRQualifiers(), |
| 2650 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2651 | if (Result.isNull()) |
| 2652 | return QualType(); |
| 2653 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2654 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2655 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2656 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2657 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2658 | NewTL.setSizeExpr(0); |
| 2659 | |
| 2660 | return Result; |
| 2661 | } |
| 2662 | |
| 2663 | template<typename Derived> |
| 2664 | QualType |
| 2665 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2666 | VariableArrayTypeLoc TL, |
| 2667 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | VariableArrayType *T = TL.getTypePtr(); |
| 2669 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2670 | if (ElementType.isNull()) |
| 2671 | return QualType(); |
| 2672 | |
| 2673 | // Array bounds are not potentially evaluated contexts |
| 2674 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2675 | |
| 2676 | Sema::OwningExprResult SizeResult |
| 2677 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2678 | if (SizeResult.isInvalid()) |
| 2679 | return QualType(); |
| 2680 | |
| 2681 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2682 | |
| 2683 | QualType Result = TL.getType(); |
| 2684 | if (getDerived().AlwaysRebuild() || |
| 2685 | ElementType != T->getElementType() || |
| 2686 | Size != T->getSizeExpr()) { |
| 2687 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2688 | T->getSizeModifier(), |
| 2689 | move(SizeResult), |
| 2690 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2691 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2692 | if (Result.isNull()) |
| 2693 | return QualType(); |
| 2694 | } |
| 2695 | else SizeResult.take(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2696 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2697 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2698 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2699 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2700 | NewTL.setSizeExpr(Size); |
| 2701 | |
| 2702 | return Result; |
| 2703 | } |
| 2704 | |
| 2705 | template<typename Derived> |
| 2706 | QualType |
| 2707 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2708 | DependentSizedArrayTypeLoc TL, |
| 2709 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2710 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2711 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2712 | if (ElementType.isNull()) |
| 2713 | return QualType(); |
| 2714 | |
| 2715 | // Array bounds are not potentially evaluated contexts |
| 2716 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2717 | |
| 2718 | Sema::OwningExprResult SizeResult |
| 2719 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2720 | if (SizeResult.isInvalid()) |
| 2721 | return QualType(); |
| 2722 | |
| 2723 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2724 | |
| 2725 | QualType Result = TL.getType(); |
| 2726 | if (getDerived().AlwaysRebuild() || |
| 2727 | ElementType != T->getElementType() || |
| 2728 | Size != T->getSizeExpr()) { |
| 2729 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2730 | T->getSizeModifier(), |
| 2731 | move(SizeResult), |
| 2732 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2733 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2734 | if (Result.isNull()) |
| 2735 | return QualType(); |
| 2736 | } |
| 2737 | else SizeResult.take(); |
| 2738 | |
| 2739 | // We might have any sort of array type now, but fortunately they |
| 2740 | // all have the same location layout. |
| 2741 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2742 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2743 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2744 | NewTL.setSizeExpr(Size); |
| 2745 | |
| 2746 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | |
| 2749 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2750 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2751 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2752 | DependentSizedExtVectorTypeLoc TL, |
| 2753 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2755 | |
| 2756 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2757 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2758 | if (ElementType.isNull()) |
| 2759 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2760 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2761 | // Vector sizes are not potentially evaluated contexts |
| 2762 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2763 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2764 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2765 | if (Size.isInvalid()) |
| 2766 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2767 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2768 | QualType Result = TL.getType(); |
| 2769 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2770 | ElementType != T->getElementType() || |
| 2771 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2772 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2773 | move(Size), |
| 2774 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2775 | if (Result.isNull()) |
| 2776 | return QualType(); |
| 2777 | } |
| 2778 | else Size.take(); |
| 2779 | |
| 2780 | // Result might be dependent or not. |
| 2781 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2782 | DependentSizedExtVectorTypeLoc NewTL |
| 2783 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2784 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2785 | } else { |
| 2786 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2787 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2788 | } |
| 2789 | |
| 2790 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2791 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
| 2793 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2794 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2795 | VectorTypeLoc TL, |
| 2796 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2798 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2799 | if (ElementType.isNull()) |
| 2800 | return QualType(); |
| 2801 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | QualType Result = TL.getType(); |
| 2803 | if (getDerived().AlwaysRebuild() || |
| 2804 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2805 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2806 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2807 | if (Result.isNull()) |
| 2808 | return QualType(); |
| 2809 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2810 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2811 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2812 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2813 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2814 | return Result; |
| 2815 | } |
| 2816 | |
| 2817 | template<typename Derived> |
| 2818 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2819 | ExtVectorTypeLoc TL, |
| 2820 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2821 | VectorType *T = TL.getTypePtr(); |
| 2822 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2823 | if (ElementType.isNull()) |
| 2824 | return QualType(); |
| 2825 | |
| 2826 | QualType Result = TL.getType(); |
| 2827 | if (getDerived().AlwaysRebuild() || |
| 2828 | ElementType != T->getElementType()) { |
| 2829 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2830 | T->getNumElements(), |
| 2831 | /*FIXME*/ SourceLocation()); |
| 2832 | if (Result.isNull()) |
| 2833 | return QualType(); |
| 2834 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2835 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2836 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2837 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2838 | |
| 2839 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2840 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2841 | |
| 2842 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2843 | ParmVarDecl * |
| 2844 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2845 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2846 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2847 | if (!NewDI) |
| 2848 | return 0; |
| 2849 | |
| 2850 | if (NewDI == OldDI) |
| 2851 | return OldParm; |
| 2852 | else |
| 2853 | return ParmVarDecl::Create(SemaRef.Context, |
| 2854 | OldParm->getDeclContext(), |
| 2855 | OldParm->getLocation(), |
| 2856 | OldParm->getIdentifier(), |
| 2857 | NewDI->getType(), |
| 2858 | NewDI, |
| 2859 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2860 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2861 | /* DefArg */ NULL); |
| 2862 | } |
| 2863 | |
| 2864 | template<typename Derived> |
| 2865 | bool TreeTransform<Derived>:: |
| 2866 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2867 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2868 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2869 | FunctionProtoType *T = TL.getTypePtr(); |
| 2870 | |
| 2871 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2872 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2873 | |
| 2874 | QualType NewType; |
| 2875 | ParmVarDecl *NewParm; |
| 2876 | |
| 2877 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2878 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2879 | if (!NewParm) |
| 2880 | return true; |
| 2881 | NewType = NewParm->getType(); |
| 2882 | |
| 2883 | // Deal with the possibility that we don't have a parameter |
| 2884 | // declaration for this parameter. |
| 2885 | } else { |
| 2886 | NewParm = 0; |
| 2887 | |
| 2888 | QualType OldType = T->getArgType(i); |
| 2889 | NewType = getDerived().TransformType(OldType); |
| 2890 | if (NewType.isNull()) |
| 2891 | return true; |
| 2892 | } |
| 2893 | |
| 2894 | PTypes.push_back(NewType); |
| 2895 | PVars.push_back(NewParm); |
| 2896 | } |
| 2897 | |
| 2898 | return false; |
| 2899 | } |
| 2900 | |
| 2901 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2902 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2903 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2904 | FunctionProtoTypeLoc TL, |
| 2905 | QualType ObjectType) { |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2906 | // Transform the parameters. We do this first for the benefit of template |
| 2907 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2908 | // instantiation scope before we transform the function type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2910 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2911 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2912 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2913 | |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2914 | FunctionProtoType *T = TL.getTypePtr(); |
| 2915 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2916 | if (ResultType.isNull()) |
| 2917 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2918 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2919 | QualType Result = TL.getType(); |
| 2920 | if (getDerived().AlwaysRebuild() || |
| 2921 | ResultType != T->getResultType() || |
| 2922 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2923 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2924 | ParamTypes.data(), |
| 2925 | ParamTypes.size(), |
| 2926 | T->isVariadic(), |
| 2927 | T->getTypeQuals()); |
| 2928 | if (Result.isNull()) |
| 2929 | return QualType(); |
| 2930 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2931 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2933 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2934 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2935 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2936 | NewTL.setArg(i, ParamDecls[i]); |
| 2937 | |
| 2938 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2939 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2940 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2941 | template<typename Derived> |
| 2942 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2943 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2944 | FunctionNoProtoTypeLoc TL, |
| 2945 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2946 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2947 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2948 | if (ResultType.isNull()) |
| 2949 | return QualType(); |
| 2950 | |
| 2951 | QualType Result = TL.getType(); |
| 2952 | if (getDerived().AlwaysRebuild() || |
| 2953 | ResultType != T->getResultType()) |
| 2954 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2955 | |
| 2956 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2957 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2958 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2959 | |
| 2960 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2962 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2963 | template<typename Derived> QualType |
| 2964 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2965 | UnresolvedUsingTypeLoc TL, |
| 2966 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2967 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2968 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2969 | if (!D) |
| 2970 | return QualType(); |
| 2971 | |
| 2972 | QualType Result = TL.getType(); |
| 2973 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2974 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2975 | if (Result.isNull()) |
| 2976 | return QualType(); |
| 2977 | } |
| 2978 | |
| 2979 | // We might get an arbitrary type spec type back. We should at |
| 2980 | // least always get a type spec type, though. |
| 2981 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2982 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2983 | |
| 2984 | return Result; |
| 2985 | } |
| 2986 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2987 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2988 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2989 | TypedefTypeLoc TL, |
| 2990 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2991 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2992 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2993 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 2994 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2995 | if (!Typedef) |
| 2996 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2997 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2998 | QualType Result = TL.getType(); |
| 2999 | if (getDerived().AlwaysRebuild() || |
| 3000 | Typedef != T->getDecl()) { |
| 3001 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3002 | if (Result.isNull()) |
| 3003 | return QualType(); |
| 3004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3005 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3006 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3007 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3008 | |
| 3009 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3010 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3012 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3013 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3014 | TypeOfExprTypeLoc TL, |
| 3015 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3016 | // typeof expressions are not potentially evaluated contexts |
| 3017 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3019 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3020 | if (E.isInvalid()) |
| 3021 | return QualType(); |
| 3022 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3023 | QualType Result = TL.getType(); |
| 3024 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3025 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3026 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3027 | if (Result.isNull()) |
| 3028 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3029 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3030 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3032 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3033 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3034 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3035 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3036 | |
| 3037 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
| 3040 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3041 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3042 | TypeOfTypeLoc TL, |
| 3043 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3044 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3045 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3046 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3047 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3049 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3050 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3051 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3052 | if (Result.isNull()) |
| 3053 | return QualType(); |
| 3054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3055 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3056 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3057 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3058 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3059 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3060 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3061 | |
| 3062 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3063 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3064 | |
| 3065 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3066 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3067 | DecltypeTypeLoc TL, |
| 3068 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3069 | DecltypeType *T = TL.getTypePtr(); |
| 3070 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3071 | // decltype expressions are not potentially evaluated contexts |
| 3072 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3073 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3074 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3075 | if (E.isInvalid()) |
| 3076 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3078 | QualType Result = TL.getType(); |
| 3079 | if (getDerived().AlwaysRebuild() || |
| 3080 | E.get() != T->getUnderlyingExpr()) { |
| 3081 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3082 | if (Result.isNull()) |
| 3083 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3084 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3085 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3086 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3087 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3088 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3089 | |
| 3090 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3094 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3095 | RecordTypeLoc TL, |
| 3096 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3097 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3098 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3099 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3100 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3101 | if (!Record) |
| 3102 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3104 | QualType Result = TL.getType(); |
| 3105 | if (getDerived().AlwaysRebuild() || |
| 3106 | Record != T->getDecl()) { |
| 3107 | Result = getDerived().RebuildRecordType(Record); |
| 3108 | if (Result.isNull()) |
| 3109 | return QualType(); |
| 3110 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3112 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3113 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3114 | |
| 3115 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3116 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3117 | |
| 3118 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3119 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3120 | EnumTypeLoc TL, |
| 3121 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3122 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3123 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3124 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3125 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3126 | if (!Enum) |
| 3127 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3128 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3129 | QualType Result = TL.getType(); |
| 3130 | if (getDerived().AlwaysRebuild() || |
| 3131 | Enum != T->getDecl()) { |
| 3132 | Result = getDerived().RebuildEnumType(Enum); |
| 3133 | if (Result.isNull()) |
| 3134 | return QualType(); |
| 3135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3136 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3137 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3138 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3139 | |
| 3140 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3141 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3142 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3143 | template<typename Derived> |
| 3144 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3145 | TypeLocBuilder &TLB, |
| 3146 | InjectedClassNameTypeLoc TL, |
| 3147 | QualType ObjectType) { |
| 3148 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3149 | TL.getTypePtr()->getDecl()); |
| 3150 | if (!D) return QualType(); |
| 3151 | |
| 3152 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3153 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3154 | return T; |
| 3155 | } |
| 3156 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3157 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3158 | template<typename Derived> |
| 3159 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3160 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3161 | TemplateTypeParmTypeLoc TL, |
| 3162 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3163 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3167 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3168 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3169 | SubstTemplateTypeParmTypeLoc TL, |
| 3170 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3171 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3175 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3176 | const TemplateSpecializationType *TST, |
| 3177 | QualType ObjectType) { |
| 3178 | // FIXME: this entire method is a temporary workaround; callers |
| 3179 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3180 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3181 | // Fake up a TemplateSpecializationTypeLoc. |
| 3182 | TypeLocBuilder TLB; |
| 3183 | TemplateSpecializationTypeLoc TL |
| 3184 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3185 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3186 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3187 | |
| 3188 | TL.setTemplateNameLoc(BaseLoc); |
| 3189 | TL.setLAngleLoc(BaseLoc); |
| 3190 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3191 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3192 | const TemplateArgument &TA = TST->getArg(i); |
| 3193 | TemplateArgumentLoc TAL; |
| 3194 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3195 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3196 | } |
| 3197 | |
| 3198 | TypeLocBuilder IgnoredTLB; |
| 3199 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3200 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3202 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3203 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3204 | TypeLocBuilder &TLB, |
| 3205 | TemplateSpecializationTypeLoc TL, |
| 3206 | QualType ObjectType) { |
| 3207 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3208 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3209 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3210 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3211 | if (Template.isNull()) |
| 3212 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3213 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3214 | TemplateArgumentListInfo NewTemplateArgs; |
| 3215 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3216 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3217 | |
| 3218 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3219 | TemplateArgumentLoc Loc; |
| 3220 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3221 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3222 | NewTemplateArgs.addArgument(Loc); |
| 3223 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3224 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3225 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3226 | |
| 3227 | QualType Result = |
| 3228 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3229 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3230 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3231 | |
| 3232 | if (!Result.isNull()) { |
| 3233 | TemplateSpecializationTypeLoc NewTL |
| 3234 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3235 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3236 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3237 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3238 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3239 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3242 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | |
| 3245 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3246 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3247 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 3248 | ElaboratedTypeLoc TL, |
| 3249 | QualType ObjectType) { |
| 3250 | ElaboratedType *T = TL.getTypePtr(); |
| 3251 | |
| 3252 | NestedNameSpecifier *NNS = 0; |
| 3253 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 3254 | if (T->getQualifier() != 0) { |
| 3255 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame^] | 3256 | SourceRange(), |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3257 | ObjectType); |
| 3258 | if (!NNS) |
| 3259 | return QualType(); |
| 3260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame^] | 3262 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3263 | if (Named.isNull()) |
| 3264 | return QualType(); |
| 3265 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3266 | QualType Result = TL.getType(); |
| 3267 | if (getDerived().AlwaysRebuild() || |
| 3268 | NNS != T->getQualifier() || |
| 3269 | Named != T->getNamedType()) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3270 | Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, Named); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3271 | if (Result.isNull()) |
| 3272 | return QualType(); |
| 3273 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3274 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3275 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame^] | 3276 | NewTL.setNameLoc(TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3277 | |
| 3278 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3279 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3280 | |
| 3281 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3282 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3283 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3284 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3285 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3286 | |
| 3287 | /* FIXME: preserve source information better than this */ |
| 3288 | SourceRange SR(TL.getNameLoc()); |
| 3289 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3290 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3291 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3292 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3293 | if (!NNS) |
| 3294 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3296 | QualType Result; |
| 3297 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3298 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3300 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3301 | if (NewTemplateId.isNull()) |
| 3302 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3304 | if (!getDerived().AlwaysRebuild() && |
| 3305 | NNS == T->getQualifier() && |
| 3306 | NewTemplateId == QualType(TemplateId, 0)) |
| 3307 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3309 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3310 | NewTemplateId); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3311 | } else { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3312 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3313 | T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3314 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3315 | if (Result.isNull()) |
| 3316 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3317 | |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame^] | 3318 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 3319 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3320 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3321 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3322 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3323 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3324 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3325 | QualType |
| 3326 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3327 | ObjCInterfaceTypeLoc TL, |
| 3328 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3329 | // ObjCInterfaceType is never dependent. |
| 3330 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3331 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 | |
| 3333 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3334 | QualType |
| 3335 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3336 | ObjCObjectPointerTypeLoc TL, |
| 3337 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3338 | // ObjCObjectPointerType is never dependent. |
| 3339 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3340 | } |
| 3341 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3342 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | // Statement transformation |
| 3344 | //===----------------------------------------------------------------------===// |
| 3345 | template<typename Derived> |
| 3346 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3347 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3348 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | template<typename Derived> |
| 3352 | Sema::OwningStmtResult |
| 3353 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3354 | return getDerived().TransformCompoundStmt(S, false); |
| 3355 | } |
| 3356 | |
| 3357 | template<typename Derived> |
| 3358 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3360 | bool IsStmtExpr) { |
| 3361 | bool SubStmtChanged = false; |
| 3362 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3363 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3364 | B != BEnd; ++B) { |
| 3365 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3366 | if (Result.isInvalid()) |
| 3367 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3368 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3369 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3370 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3371 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3372 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3373 | if (!getDerived().AlwaysRebuild() && |
| 3374 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3375 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3376 | |
| 3377 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3378 | move_arg(Statements), |
| 3379 | S->getRBracLoc(), |
| 3380 | IsStmtExpr); |
| 3381 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3382 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3383 | template<typename Derived> |
| 3384 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3385 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3386 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3387 | { |
| 3388 | // The case value expressions are not potentially evaluated. |
| 3389 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3390 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3391 | // Transform the left-hand case value. |
| 3392 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3393 | if (LHS.isInvalid()) |
| 3394 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3396 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3397 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3398 | if (RHS.isInvalid()) |
| 3399 | return SemaRef.StmtError(); |
| 3400 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3401 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3402 | // Build the case statement. |
| 3403 | // Case statements are always rebuilt so that they will attached to their |
| 3404 | // transformed switch statement. |
| 3405 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3406 | move(LHS), |
| 3407 | S->getEllipsisLoc(), |
| 3408 | move(RHS), |
| 3409 | S->getColonLoc()); |
| 3410 | if (Case.isInvalid()) |
| 3411 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3412 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3413 | // Transform the statement following the case |
| 3414 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3415 | if (SubStmt.isInvalid()) |
| 3416 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3418 | // Attach the body to the case statement |
| 3419 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3420 | } |
| 3421 | |
| 3422 | template<typename Derived> |
| 3423 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3424 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3425 | // Transform the statement following the default case |
| 3426 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3427 | if (SubStmt.isInvalid()) |
| 3428 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3429 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3430 | // Default statements are always rebuilt |
| 3431 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3432 | move(SubStmt)); |
| 3433 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3434 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3435 | template<typename Derived> |
| 3436 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3439 | if (SubStmt.isInvalid()) |
| 3440 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | // FIXME: Pass the real colon location in. |
| 3443 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3444 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3445 | move(SubStmt)); |
| 3446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3447 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3448 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | Sema::OwningStmtResult |
| 3450 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3451 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3452 | OwningExprResult Cond(SemaRef); |
| 3453 | VarDecl *ConditionVar = 0; |
| 3454 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3455 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3456 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3457 | getDerived().TransformDefinition( |
| 3458 | S->getConditionVariable()->getLocation(), |
| 3459 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3460 | if (!ConditionVar) |
| 3461 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3462 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3463 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3464 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3465 | if (Cond.isInvalid()) |
| 3466 | return SemaRef.StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3467 | |
| 3468 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3469 | if (S->getCond()) { |
| 3470 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3471 | S->getIfLoc(), |
| 3472 | move(Cond)); |
| 3473 | if (CondE.isInvalid()) |
| 3474 | return getSema().StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3475 | |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3476 | Cond = move(CondE); |
| 3477 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3478 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3479 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3480 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3481 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3482 | return SemaRef.StmtError(); |
| 3483 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3484 | // Transform the "then" branch. |
| 3485 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3486 | if (Then.isInvalid()) |
| 3487 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3489 | // Transform the "else" branch. |
| 3490 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3491 | if (Else.isInvalid()) |
| 3492 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3493 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3494 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3495 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3496 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3497 | Then.get() == S->getThen() && |
| 3498 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3499 | return SemaRef.Owned(S->Retain()); |
| 3500 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3501 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3502 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | template<typename Derived> |
| 3507 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3508 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3509 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3510 | OwningExprResult Cond(SemaRef); |
| 3511 | VarDecl *ConditionVar = 0; |
| 3512 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3513 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3514 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3515 | getDerived().TransformDefinition( |
| 3516 | S->getConditionVariable()->getLocation(), |
| 3517 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3518 | if (!ConditionVar) |
| 3519 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3520 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3521 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3522 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3523 | if (Cond.isInvalid()) |
| 3524 | return SemaRef.StmtError(); |
| 3525 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3527 | // Rebuild the switch statement. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3528 | OwningStmtResult Switch |
| 3529 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3530 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3531 | if (Switch.isInvalid()) |
| 3532 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3534 | // Transform the body of the switch statement. |
| 3535 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3536 | if (Body.isInvalid()) |
| 3537 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3538 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3539 | // Complete the switch statement. |
| 3540 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3541 | move(Body)); |
| 3542 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3544 | template<typename Derived> |
| 3545 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3546 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3547 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3548 | OwningExprResult Cond(SemaRef); |
| 3549 | VarDecl *ConditionVar = 0; |
| 3550 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3551 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3552 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3553 | getDerived().TransformDefinition( |
| 3554 | S->getConditionVariable()->getLocation(), |
| 3555 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3556 | if (!ConditionVar) |
| 3557 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3558 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3559 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3560 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3561 | if (Cond.isInvalid()) |
| 3562 | return SemaRef.StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3563 | |
| 3564 | if (S->getCond()) { |
| 3565 | // Convert the condition to a boolean value. |
| 3566 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3567 | S->getWhileLoc(), |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3568 | move(Cond)); |
| 3569 | if (CondE.isInvalid()) |
| 3570 | return getSema().StmtError(); |
| 3571 | Cond = move(CondE); |
| 3572 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3575 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3576 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3577 | return SemaRef.StmtError(); |
| 3578 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3579 | // Transform the body |
| 3580 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3581 | if (Body.isInvalid()) |
| 3582 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3584 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3585 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3586 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3587 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | return SemaRef.Owned(S->Retain()); |
| 3589 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3590 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3591 | ConditionVar, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3593 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3594 | template<typename Derived> |
| 3595 | Sema::OwningStmtResult |
| 3596 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3597 | // Transform the body |
| 3598 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3599 | if (Body.isInvalid()) |
| 3600 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3602 | // Transform the condition |
| 3603 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3604 | if (Cond.isInvalid()) |
| 3605 | return SemaRef.StmtError(); |
| 3606 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3607 | if (!getDerived().AlwaysRebuild() && |
| 3608 | Cond.get() == S->getCond() && |
| 3609 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | return SemaRef.Owned(S->Retain()); |
| 3611 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3612 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3613 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3614 | S->getRParenLoc()); |
| 3615 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3617 | template<typename Derived> |
| 3618 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3619 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3620 | // Transform the initialization statement |
| 3621 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3622 | if (Init.isInvalid()) |
| 3623 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3624 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3625 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3626 | OwningExprResult Cond(SemaRef); |
| 3627 | VarDecl *ConditionVar = 0; |
| 3628 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3629 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3630 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3631 | getDerived().TransformDefinition( |
| 3632 | S->getConditionVariable()->getLocation(), |
| 3633 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3634 | if (!ConditionVar) |
| 3635 | return SemaRef.StmtError(); |
| 3636 | } else { |
| 3637 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3638 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3639 | if (Cond.isInvalid()) |
| 3640 | return SemaRef.StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3641 | |
| 3642 | if (S->getCond()) { |
| 3643 | // Convert the condition to a boolean value. |
| 3644 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3645 | S->getForLoc(), |
| 3646 | move(Cond)); |
| 3647 | if (CondE.isInvalid()) |
| 3648 | return getSema().StmtError(); |
| 3649 | |
| 3650 | Cond = move(CondE); |
| 3651 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3654 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3655 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3656 | return SemaRef.StmtError(); |
| 3657 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3658 | // Transform the increment |
| 3659 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3660 | if (Inc.isInvalid()) |
| 3661 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3663 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3664 | if (S->getInc() && !FullInc->get()) |
| 3665 | return SemaRef.StmtError(); |
| 3666 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3667 | // Transform the body |
| 3668 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3669 | if (Body.isInvalid()) |
| 3670 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3671 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3672 | if (!getDerived().AlwaysRebuild() && |
| 3673 | Init.get() == S->getInit() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3674 | FullCond->get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3675 | Inc.get() == S->getInc() && |
| 3676 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | return SemaRef.Owned(S->Retain()); |
| 3678 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3679 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3680 | move(Init), FullCond, ConditionVar, |
| 3681 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | Sema::OwningStmtResult |
| 3686 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3687 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3689 | S->getLabel()); |
| 3690 | } |
| 3691 | |
| 3692 | template<typename Derived> |
| 3693 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3695 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3696 | if (Target.isInvalid()) |
| 3697 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3698 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3699 | if (!getDerived().AlwaysRebuild() && |
| 3700 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3701 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3702 | |
| 3703 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3704 | move(Target)); |
| 3705 | } |
| 3706 | |
| 3707 | template<typename Derived> |
| 3708 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3709 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3710 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3711 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3713 | template<typename Derived> |
| 3714 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3715 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3716 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3717 | } |
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 | template<typename Derived> |
| 3720 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3722 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3723 | if (Result.isInvalid()) |
| 3724 | return SemaRef.StmtError(); |
| 3725 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3727 | // to tell whether the return type of the function has changed. |
| 3728 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3729 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3731 | template<typename Derived> |
| 3732 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3733 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3734 | bool DeclChanged = false; |
| 3735 | llvm::SmallVector<Decl *, 4> Decls; |
| 3736 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3737 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3738 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3739 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3740 | if (!Transformed) |
| 3741 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3743 | if (Transformed != *D) |
| 3744 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3746 | Decls.push_back(Transformed); |
| 3747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3748 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3749 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3750 | return SemaRef.Owned(S->Retain()); |
| 3751 | |
| 3752 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3753 | S->getStartLoc(), S->getEndLoc()); |
| 3754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3756 | template<typename Derived> |
| 3757 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3758 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3759 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | template<typename Derived> |
| 3764 | Sema::OwningStmtResult |
| 3765 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3766 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3767 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3768 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3769 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3770 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3771 | OwningExprResult AsmString(SemaRef); |
| 3772 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3773 | |
| 3774 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3775 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3776 | // Go through the outputs. |
| 3777 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3778 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3779 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3780 | // No need to transform the constraint literal. |
| 3781 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3782 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3783 | // Transform the output expr. |
| 3784 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3785 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3786 | if (Result.isInvalid()) |
| 3787 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3788 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3789 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3790 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3791 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3792 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3793 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3794 | // Go through the inputs. |
| 3795 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3796 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3797 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3798 | // No need to transform the constraint literal. |
| 3799 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3800 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3801 | // Transform the input expr. |
| 3802 | Expr *InputExpr = S->getInputExpr(I); |
| 3803 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3804 | if (Result.isInvalid()) |
| 3805 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3806 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3807 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3808 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3809 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3810 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3811 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3812 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3813 | return SemaRef.Owned(S->Retain()); |
| 3814 | |
| 3815 | // Go through the clobbers. |
| 3816 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3817 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3818 | |
| 3819 | // No need to transform the asm string literal. |
| 3820 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3821 | |
| 3822 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3823 | S->isSimple(), |
| 3824 | S->isVolatile(), |
| 3825 | S->getNumOutputs(), |
| 3826 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3827 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3828 | move_arg(Constraints), |
| 3829 | move_arg(Exprs), |
| 3830 | move(AsmString), |
| 3831 | move_arg(Clobbers), |
| 3832 | S->getRParenLoc(), |
| 3833 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | |
| 3837 | template<typename Derived> |
| 3838 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3840 | // Transform the body of the @try. |
| 3841 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3842 | if (TryBody.isInvalid()) |
| 3843 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3845 | // Transform the @catch statements (if present). |
| 3846 | bool AnyCatchChanged = false; |
| 3847 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3848 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3849 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3850 | if (Catch.isInvalid()) |
| 3851 | return SemaRef.StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3852 | if (Catch.get() != S->getCatchStmt(I)) |
| 3853 | AnyCatchChanged = true; |
| 3854 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3855 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3856 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3857 | // Transform the @finally statement (if present). |
| 3858 | OwningStmtResult Finally(SemaRef); |
| 3859 | if (S->getFinallyStmt()) { |
| 3860 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3861 | if (Finally.isInvalid()) |
| 3862 | return SemaRef.StmtError(); |
| 3863 | } |
| 3864 | |
| 3865 | // If nothing changed, just retain this statement. |
| 3866 | if (!getDerived().AlwaysRebuild() && |
| 3867 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3868 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3869 | Finally.get() == S->getFinallyStmt()) |
| 3870 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3872 | // Build a new statement. |
| 3873 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3874 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3877 | template<typename Derived> |
| 3878 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3880 | // Transform the @catch parameter, if there is one. |
| 3881 | VarDecl *Var = 0; |
| 3882 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3883 | TypeSourceInfo *TSInfo = 0; |
| 3884 | if (FromVar->getTypeSourceInfo()) { |
| 3885 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3886 | if (!TSInfo) |
| 3887 | return SemaRef.StmtError(); |
| 3888 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3889 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3890 | QualType T; |
| 3891 | if (TSInfo) |
| 3892 | T = TSInfo->getType(); |
| 3893 | else { |
| 3894 | T = getDerived().TransformType(FromVar->getType()); |
| 3895 | if (T.isNull()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3896 | return SemaRef.StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3897 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3898 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3899 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3900 | if (!Var) |
| 3901 | return SemaRef.StmtError(); |
| 3902 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3904 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3905 | if (Body.isInvalid()) |
| 3906 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3907 | |
| 3908 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3909 | S->getRParenLoc(), |
| 3910 | Var, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3911 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3912 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3913 | template<typename Derived> |
| 3914 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3916 | // Transform the body. |
| 3917 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 3918 | if (Body.isInvalid()) |
| 3919 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3920 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3921 | // If nothing changed, just retain this statement. |
| 3922 | if (!getDerived().AlwaysRebuild() && |
| 3923 | Body.get() == S->getFinallyBody()) |
| 3924 | return SemaRef.Owned(S->Retain()); |
| 3925 | |
| 3926 | // Build a new statement. |
| 3927 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 3928 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3929 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3930 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3931 | template<typename Derived> |
| 3932 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3933 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3934 | OwningExprResult Operand(SemaRef); |
| 3935 | if (S->getThrowExpr()) { |
| 3936 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3937 | if (Operand.isInvalid()) |
| 3938 | return getSema().StmtError(); |
| 3939 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3941 | if (!getDerived().AlwaysRebuild() && |
| 3942 | Operand.get() == S->getThrowExpr()) |
| 3943 | return getSema().Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3944 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3945 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3946 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3947 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3948 | template<typename Derived> |
| 3949 | Sema::OwningStmtResult |
| 3950 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3951 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3952 | // Transform the object we are locking. |
| 3953 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3954 | if (Object.isInvalid()) |
| 3955 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3956 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3957 | // Transform the body. |
| 3958 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3959 | if (Body.isInvalid()) |
| 3960 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3961 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3962 | // If nothing change, just retain the current statement. |
| 3963 | if (!getDerived().AlwaysRebuild() && |
| 3964 | Object.get() == S->getSynchExpr() && |
| 3965 | Body.get() == S->getSynchBody()) |
| 3966 | return SemaRef.Owned(S->Retain()); |
| 3967 | |
| 3968 | // Build a new statement. |
| 3969 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 3970 | move(Object), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | template<typename Derived> |
| 3974 | Sema::OwningStmtResult |
| 3975 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3977 | // Transform the element statement. |
| 3978 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 3979 | if (Element.isInvalid()) |
| 3980 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3981 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3982 | // Transform the collection expression. |
| 3983 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 3984 | if (Collection.isInvalid()) |
| 3985 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3987 | // Transform the body. |
| 3988 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3989 | if (Body.isInvalid()) |
| 3990 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3991 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3992 | // If nothing changed, just retain this statement. |
| 3993 | if (!getDerived().AlwaysRebuild() && |
| 3994 | Element.get() == S->getElement() && |
| 3995 | Collection.get() == S->getCollection() && |
| 3996 | Body.get() == S->getBody()) |
| 3997 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3998 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3999 | // Build a new statement. |
| 4000 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4001 | /*FIXME:*/S->getForLoc(), |
| 4002 | move(Element), |
| 4003 | move(Collection), |
| 4004 | S->getRParenLoc(), |
| 4005 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | |
| 4009 | template<typename Derived> |
| 4010 | Sema::OwningStmtResult |
| 4011 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4012 | // Transform the exception declaration, if any. |
| 4013 | VarDecl *Var = 0; |
| 4014 | if (S->getExceptionDecl()) { |
| 4015 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4016 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4017 | ExceptionDecl->getDeclName()); |
| 4018 | |
| 4019 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4020 | if (T.isNull()) |
| 4021 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4023 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4024 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4025 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4026 | ExceptionDecl->getIdentifier(), |
| 4027 | ExceptionDecl->getLocation(), |
| 4028 | /*FIXME: Inaccurate*/ |
| 4029 | SourceRange(ExceptionDecl->getLocation())); |
| 4030 | if (!Var || Var->isInvalidDecl()) { |
| 4031 | if (Var) |
| 4032 | Var->Destroy(SemaRef.Context); |
| 4033 | return SemaRef.StmtError(); |
| 4034 | } |
| 4035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4037 | // Transform the actual exception handler. |
| 4038 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 4039 | if (Handler.isInvalid()) { |
| 4040 | if (Var) |
| 4041 | Var->Destroy(SemaRef.Context); |
| 4042 | return SemaRef.StmtError(); |
| 4043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4045 | if (!getDerived().AlwaysRebuild() && |
| 4046 | !Var && |
| 4047 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4048 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4049 | |
| 4050 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4051 | Var, |
| 4052 | move(Handler)); |
| 4053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4055 | template<typename Derived> |
| 4056 | Sema::OwningStmtResult |
| 4057 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4058 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4060 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4061 | if (TryBlock.isInvalid()) |
| 4062 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4064 | // Transform the handlers. |
| 4065 | bool HandlerChanged = false; |
| 4066 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4067 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4069 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4070 | if (Handler.isInvalid()) |
| 4071 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4072 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4073 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4074 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4075 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4077 | if (!getDerived().AlwaysRebuild() && |
| 4078 | TryBlock.get() == S->getTryBlock() && |
| 4079 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4081 | |
| 4082 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4086 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4087 | // Expression transformation |
| 4088 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | template<typename Derived> |
| 4090 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4091 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4094 | |
| 4095 | template<typename Derived> |
| 4096 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4097 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4098 | NestedNameSpecifier *Qualifier = 0; |
| 4099 | if (E->getQualifier()) { |
| 4100 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4101 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4102 | if (!Qualifier) |
| 4103 | return SemaRef.ExprError(); |
| 4104 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4105 | |
| 4106 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4107 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4108 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4109 | if (!ND) |
| 4110 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4111 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4112 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4113 | Qualifier == E->getQualifier() && |
| 4114 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4115 | !E->hasExplicitTemplateArgumentList()) { |
| 4116 | |
| 4117 | // Mark it referenced in the new context regardless. |
| 4118 | // FIXME: this is a bit instantiation-specific. |
| 4119 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4120 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4121 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4122 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4123 | |
| 4124 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4125 | if (E->hasExplicitTemplateArgumentList()) { |
| 4126 | TemplateArgs = &TransArgs; |
| 4127 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4128 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4129 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4130 | TemplateArgumentLoc Loc; |
| 4131 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4132 | return SemaRef.ExprError(); |
| 4133 | TransArgs.addArgument(Loc); |
| 4134 | } |
| 4135 | } |
| 4136 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4137 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4138 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4142 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4143 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4144 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4147 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4149 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4153 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4155 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4156 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4161 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4162 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4163 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4164 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4165 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4166 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4167 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | return SemaRef.Owned(E->Retain()); |
| 4169 | } |
| 4170 | |
| 4171 | template<typename Derived> |
| 4172 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4173 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4174 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4175 | if (SubExpr.isInvalid()) |
| 4176 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4178 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4179 | return SemaRef.Owned(E->Retain()); |
| 4180 | |
| 4181 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | E->getRParen()); |
| 4183 | } |
| 4184 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4185 | template<typename Derived> |
| 4186 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4187 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4188 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4189 | if (SubExpr.isInvalid()) |
| 4190 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | return SemaRef.Owned(E->Retain()); |
| 4194 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4195 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4196 | E->getOpcode(), |
| 4197 | move(SubExpr)); |
| 4198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | Sema::OwningExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4202 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4203 | // Transform the type. |
| 4204 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4205 | if (!Type) |
| 4206 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4207 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4208 | // Transform all of the components into components similar to what the |
| 4209 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4210 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4211 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4212 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4213 | // template code that we don't care. |
| 4214 | bool ExprChanged = false; |
| 4215 | typedef Action::OffsetOfComponent Component; |
| 4216 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4217 | llvm::SmallVector<Component, 4> Components; |
| 4218 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4219 | const Node &ON = E->getComponent(I); |
| 4220 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4221 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4222 | Comp.LocStart = ON.getRange().getBegin(); |
| 4223 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4224 | switch (ON.getKind()) { |
| 4225 | case Node::Array: { |
| 4226 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4227 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4228 | if (Index.isInvalid()) |
| 4229 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4230 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4231 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4232 | Comp.isBrackets = true; |
| 4233 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4234 | break; |
| 4235 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4237 | case Node::Field: |
| 4238 | case Node::Identifier: |
| 4239 | Comp.isBrackets = false; |
| 4240 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4241 | if (!Comp.U.IdentInfo) |
| 4242 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4243 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4244 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4245 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4246 | case Node::Base: |
| 4247 | // Will be recomputed during the rebuild. |
| 4248 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4249 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4250 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4251 | Components.push_back(Comp); |
| 4252 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4253 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4254 | // If nothing changed, retain the existing expression. |
| 4255 | if (!getDerived().AlwaysRebuild() && |
| 4256 | Type == E->getTypeSourceInfo() && |
| 4257 | !ExprChanged) |
| 4258 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4259 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4260 | // Build a new offsetof expression. |
| 4261 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4262 | Components.data(), Components.size(), |
| 4263 | E->getRParenLoc()); |
| 4264 | } |
| 4265 | |
| 4266 | template<typename Derived> |
| 4267 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4268 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4269 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4270 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4271 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4272 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4273 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4274 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4276 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4277 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4278 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4279 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4280 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | E->getSourceRange()); |
| 4282 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4284 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4285 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4286 | // C++0x [expr.sizeof]p1: |
| 4287 | // The operand is either an expression, which is an unevaluated operand |
| 4288 | // [...] |
| 4289 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4291 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4292 | if (SubExpr.isInvalid()) |
| 4293 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4294 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4295 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4296 | return SemaRef.Owned(E->Retain()); |
| 4297 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4298 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4299 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4300 | E->isSizeOf(), |
| 4301 | E->getSourceRange()); |
| 4302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4305 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4306 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4307 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4308 | if (LHS.isInvalid()) |
| 4309 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4310 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4312 | if (RHS.isInvalid()) |
| 4313 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
| 4315 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4316 | if (!getDerived().AlwaysRebuild() && |
| 4317 | LHS.get() == E->getLHS() && |
| 4318 | RHS.get() == E->getRHS()) |
| 4319 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4320 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4321 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4322 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4323 | move(RHS), |
| 4324 | E->getRBracketLoc()); |
| 4325 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4326 | |
| 4327 | template<typename Derived> |
| 4328 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4329 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4330 | // Transform the callee. |
| 4331 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4332 | if (Callee.isInvalid()) |
| 4333 | return SemaRef.ExprError(); |
| 4334 | |
| 4335 | // Transform arguments. |
| 4336 | bool ArgChanged = false; |
| 4337 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4338 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4339 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4340 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4341 | if (Arg.isInvalid()) |
| 4342 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4343 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4344 | // FIXME: Wrong source location information for the ','. |
| 4345 | FakeCommaLocs.push_back( |
| 4346 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
| 4348 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4349 | Args.push_back(Arg.takeAs<Expr>()); |
| 4350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4352 | if (!getDerived().AlwaysRebuild() && |
| 4353 | Callee.get() == E->getCallee() && |
| 4354 | !ArgChanged) |
| 4355 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4357 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4360 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4361 | move_arg(Args), |
| 4362 | FakeCommaLocs.data(), |
| 4363 | E->getRParenLoc()); |
| 4364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
| 4366 | template<typename Derived> |
| 4367 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4368 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4369 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4370 | if (Base.isInvalid()) |
| 4371 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4373 | NestedNameSpecifier *Qualifier = 0; |
| 4374 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4375 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4376 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4377 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4378 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4379 | return SemaRef.ExprError(); |
| 4380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4381 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4382 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4383 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4384 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4385 | if (!Member) |
| 4386 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4388 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4389 | if (FoundDecl == E->getMemberDecl()) { |
| 4390 | FoundDecl = Member; |
| 4391 | } else { |
| 4392 | FoundDecl = cast_or_null<NamedDecl>( |
| 4393 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4394 | if (!FoundDecl) |
| 4395 | return SemaRef.ExprError(); |
| 4396 | } |
| 4397 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | if (!getDerived().AlwaysRebuild() && |
| 4399 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4400 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4401 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4402 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4403 | !E->hasExplicitTemplateArgumentList()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4404 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4405 | // Mark it referenced in the new context regardless. |
| 4406 | // FIXME: this is a bit instantiation-specific. |
| 4407 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4409 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4411 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4412 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4413 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4414 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4415 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4416 | TemplateArgumentLoc Loc; |
| 4417 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4418 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4419 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4420 | } |
| 4421 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | // FIXME: Bogus source location for the operator |
| 4424 | SourceLocation FakeOperatorLoc |
| 4425 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4426 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4427 | // FIXME: to do this check properly, we will need to preserve the |
| 4428 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4429 | // base (and therefore couldn't do the check) and a |
| 4430 | // nested-name-qualifier (and therefore could do the lookup). |
| 4431 | NamedDecl *FirstQualifierInScope = 0; |
| 4432 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4433 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4434 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4435 | Qualifier, |
| 4436 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4438 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4439 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4440 | (E->hasExplicitTemplateArgumentList() |
| 4441 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4442 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | } |
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 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4447 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4449 | if (LHS.isInvalid()) |
| 4450 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4453 | if (RHS.isInvalid()) |
| 4454 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4455 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | if (!getDerived().AlwaysRebuild() && |
| 4457 | LHS.get() == E->getLHS() && |
| 4458 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4459 | return SemaRef.Owned(E->Retain()); |
| 4460 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4461 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4462 | move(LHS), move(RHS)); |
| 4463 | } |
| 4464 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | Sema::OwningExprResult |
| 4467 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4468 | CompoundAssignOperator *E) { |
| 4469 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4473 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4474 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4476 | if (Cond.isInvalid()) |
| 4477 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4480 | if (LHS.isInvalid()) |
| 4481 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4484 | if (RHS.isInvalid()) |
| 4485 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4487 | if (!getDerived().AlwaysRebuild() && |
| 4488 | Cond.get() == E->getCond() && |
| 4489 | LHS.get() == E->getLHS() && |
| 4490 | RHS.get() == E->getRHS()) |
| 4491 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | |
| 4493 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4494 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4495 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4496 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | move(RHS)); |
| 4498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4499 | |
| 4500 | template<typename Derived> |
| 4501 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4502 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4503 | // Implicit casts are eliminated during transformation, since they |
| 4504 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4505 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4507 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4508 | template<typename Derived> |
| 4509 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4510 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4511 | TypeSourceInfo *OldT; |
| 4512 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4513 | { |
| 4514 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4516 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4517 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4518 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4519 | OldT = E->getTypeInfoAsWritten(); |
| 4520 | NewT = getDerived().TransformType(OldT); |
| 4521 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | return SemaRef.ExprError(); |
| 4523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4524 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4525 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4526 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4527 | if (SubExpr.isInvalid()) |
| 4528 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4530 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4531 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | return SemaRef.Owned(E->Retain()); |
| 4534 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4535 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4536 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4537 | E->getRParenLoc(), |
| 4538 | move(SubExpr)); |
| 4539 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4541 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4543 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4544 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4545 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4546 | if (!NewT) |
| 4547 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4550 | if (Init.isInvalid()) |
| 4551 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4553 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4554 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4558 | // Note: the expression type doesn't necessarily match the |
| 4559 | // type-as-written, but that's okay, because it should always be |
| 4560 | // derivable from the initializer. |
| 4561 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4562 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4563 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4564 | move(Init)); |
| 4565 | } |
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 | template<typename Derived> |
| 4568 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4569 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4571 | if (Base.isInvalid()) |
| 4572 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | if (!getDerived().AlwaysRebuild() && |
| 4575 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | return SemaRef.Owned(E->Retain()); |
| 4577 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4578 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4579 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4580 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4581 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4582 | E->getAccessorLoc(), |
| 4583 | E->getAccessor()); |
| 4584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4585 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4586 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4587 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4588 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4589 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4590 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4591 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4592 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4593 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4594 | if (Init.isInvalid()) |
| 4595 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4596 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4597 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4598 | Inits.push_back(Init.takeAs<Expr>()); |
| 4599 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4600 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4602 | return SemaRef.Owned(E->Retain()); |
| 4603 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4605 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4606 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4607 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4608 | template<typename Derived> |
| 4609 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4610 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4613 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4614 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4615 | if (Init.isInvalid()) |
| 4616 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4617 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4618 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4620 | bool ExprChanged = false; |
| 4621 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4622 | DEnd = E->designators_end(); |
| 4623 | D != DEnd; ++D) { |
| 4624 | if (D->isFieldDesignator()) { |
| 4625 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4626 | D->getDotLoc(), |
| 4627 | D->getFieldLoc())); |
| 4628 | continue; |
| 4629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4630 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4631 | if (D->isArrayDesignator()) { |
| 4632 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4633 | if (Index.isInvalid()) |
| 4634 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4635 | |
| 4636 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4638 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4640 | ArrayExprs.push_back(Index.release()); |
| 4641 | continue; |
| 4642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4643 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4647 | if (Start.isInvalid()) |
| 4648 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4650 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4651 | if (End.isInvalid()) |
| 4652 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
| 4654 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4655 | End.get(), |
| 4656 | D->getLBracketLoc(), |
| 4657 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4658 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4660 | End.get() != E->getArrayRangeEnd(*D); |
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 | ArrayExprs.push_back(Start.release()); |
| 4663 | ArrayExprs.push_back(End.release()); |
| 4664 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | if (!getDerived().AlwaysRebuild() && |
| 4667 | Init.get() == E->getInit() && |
| 4668 | !ExprChanged) |
| 4669 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4671 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4672 | E->getEqualOrColonLoc(), |
| 4673 | E->usesGNUSyntax(), move(Init)); |
| 4674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4679 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4680 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4681 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4682 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4683 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4684 | QualType T = getDerived().TransformType(E->getType()); |
| 4685 | if (T.isNull()) |
| 4686 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4688 | if (!getDerived().AlwaysRebuild() && |
| 4689 | T == E->getType()) |
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().RebuildImplicitValueInitExpr(T); |
| 4693 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4697 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4698 | // FIXME: Do we want the type as written? |
| 4699 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4701 | { |
| 4702 | // FIXME: Source location isn't quite accurate. |
| 4703 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4704 | T = getDerived().TransformType(E->getType()); |
| 4705 | if (T.isNull()) |
| 4706 | return SemaRef.ExprError(); |
| 4707 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4708 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4709 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4710 | if (SubExpr.isInvalid()) |
| 4711 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4712 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | if (!getDerived().AlwaysRebuild() && |
| 4714 | T == E->getType() && |
| 4715 | SubExpr.get() == E->getSubExpr()) |
| 4716 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4717 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4718 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4719 | T, E->getRParenLoc()); |
| 4720 | } |
| 4721 | |
| 4722 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4724 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4725 | bool ArgumentChanged = false; |
| 4726 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4727 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4728 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4729 | if (Init.isInvalid()) |
| 4730 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4733 | Inits.push_back(Init.takeAs<Expr>()); |
| 4734 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4736 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4737 | move_arg(Inits), |
| 4738 | E->getRParenLoc()); |
| 4739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4740 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4741 | /// \brief Transform an address-of-label expression. |
| 4742 | /// |
| 4743 | /// By default, the transformation of an address-of-label expression always |
| 4744 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4745 | /// the corresponding label statement by semantic analysis. |
| 4746 | template<typename Derived> |
| 4747 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4748 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4749 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4750 | E->getLabel()); |
| 4751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4752 | |
| 4753 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4754 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4755 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4756 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4757 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4758 | if (SubStmt.isInvalid()) |
| 4759 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4761 | if (!getDerived().AlwaysRebuild() && |
| 4762 | SubStmt.get() == E->getSubStmt()) |
| 4763 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | |
| 4765 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4766 | move(SubStmt), |
| 4767 | E->getRParenLoc()); |
| 4768 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4769 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4770 | template<typename Derived> |
| 4771 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4772 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | QualType T1, T2; |
| 4774 | { |
| 4775 | // FIXME: Source location isn't quite accurate. |
| 4776 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4778 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4779 | if (T1.isNull()) |
| 4780 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4781 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4782 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4783 | if (T2.isNull()) |
| 4784 | return SemaRef.ExprError(); |
| 4785 | } |
| 4786 | |
| 4787 | if (!getDerived().AlwaysRebuild() && |
| 4788 | T1 == E->getArgType1() && |
| 4789 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | return SemaRef.Owned(E->Retain()); |
| 4791 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4792 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4793 | T1, T2, E->getRParenLoc()); |
| 4794 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4795 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4796 | template<typename Derived> |
| 4797 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4798 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4800 | if (Cond.isInvalid()) |
| 4801 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4802 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4803 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4804 | if (LHS.isInvalid()) |
| 4805 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4808 | if (RHS.isInvalid()) |
| 4809 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4810 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4811 | if (!getDerived().AlwaysRebuild() && |
| 4812 | Cond.get() == E->getCond() && |
| 4813 | LHS.get() == E->getLHS() && |
| 4814 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4815 | return SemaRef.Owned(E->Retain()); |
| 4816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4818 | move(Cond), move(LHS), move(RHS), |
| 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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4823 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4824 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4825 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | template<typename Derived> |
| 4829 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4830 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4831 | switch (E->getOperator()) { |
| 4832 | case OO_New: |
| 4833 | case OO_Delete: |
| 4834 | case OO_Array_New: |
| 4835 | case OO_Array_Delete: |
| 4836 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4837 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4838 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4839 | case OO_Call: { |
| 4840 | // This is a call to an object's operator(). |
| 4841 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4842 | |
| 4843 | // Transform the object itself. |
| 4844 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4845 | if (Object.isInvalid()) |
| 4846 | return SemaRef.ExprError(); |
| 4847 | |
| 4848 | // FIXME: Poor location information |
| 4849 | SourceLocation FakeLParenLoc |
| 4850 | = SemaRef.PP.getLocForEndOfToken( |
| 4851 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4852 | |
| 4853 | // Transform the call arguments. |
| 4854 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4855 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4856 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4857 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4858 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4859 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4860 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4861 | if (Arg.isInvalid()) |
| 4862 | return SemaRef.ExprError(); |
| 4863 | |
| 4864 | // FIXME: Poor source location information. |
| 4865 | SourceLocation FakeCommaLoc |
| 4866 | = SemaRef.PP.getLocForEndOfToken( |
| 4867 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4868 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4869 | Args.push_back(Arg.release()); |
| 4870 | } |
| 4871 | |
| 4872 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4873 | move_arg(Args), |
| 4874 | FakeCommaLocs.data(), |
| 4875 | E->getLocEnd()); |
| 4876 | } |
| 4877 | |
| 4878 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4879 | case OO_##Name: |
| 4880 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4881 | #include "clang/Basic/OperatorKinds.def" |
| 4882 | case OO_Subscript: |
| 4883 | // Handled below. |
| 4884 | break; |
| 4885 | |
| 4886 | case OO_Conditional: |
| 4887 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4888 | return SemaRef.ExprError(); |
| 4889 | |
| 4890 | case OO_None: |
| 4891 | case NUM_OVERLOADED_OPERATORS: |
| 4892 | llvm_unreachable("not an overloaded operator?"); |
| 4893 | return SemaRef.ExprError(); |
| 4894 | } |
| 4895 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4897 | if (Callee.isInvalid()) |
| 4898 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4900 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4901 | if (First.isInvalid()) |
| 4902 | return SemaRef.ExprError(); |
| 4903 | |
| 4904 | OwningExprResult Second(SemaRef); |
| 4905 | if (E->getNumArgs() == 2) { |
| 4906 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4907 | if (Second.isInvalid()) |
| 4908 | return SemaRef.ExprError(); |
| 4909 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4911 | if (!getDerived().AlwaysRebuild() && |
| 4912 | Callee.get() == E->getCallee() && |
| 4913 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4915 | return SemaRef.Owned(E->Retain()); |
| 4916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4917 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4918 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4919 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4920 | move(First), |
| 4921 | move(Second)); |
| 4922 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4923 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4924 | template<typename Derived> |
| 4925 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4926 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4927 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4928 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4930 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4931 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4932 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4933 | TypeSourceInfo *OldT; |
| 4934 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4935 | { |
| 4936 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4937 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4938 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4939 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4940 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4941 | OldT = E->getTypeInfoAsWritten(); |
| 4942 | NewT = getDerived().TransformType(OldT); |
| 4943 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4944 | return SemaRef.ExprError(); |
| 4945 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4946 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4947 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4948 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4949 | if (SubExpr.isInvalid()) |
| 4950 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4951 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4952 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4953 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4954 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4955 | return SemaRef.Owned(E->Retain()); |
| 4956 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4957 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4958 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4959 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4960 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4961 | SourceLocation FakeRParenLoc |
| 4962 | = SemaRef.PP.getLocForEndOfToken( |
| 4963 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4964 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4965 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4966 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4967 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4968 | FakeRAngleLoc, |
| 4969 | FakeRAngleLoc, |
| 4970 | move(SubExpr), |
| 4971 | FakeRParenLoc); |
| 4972 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4973 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4974 | template<typename Derived> |
| 4975 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4976 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4977 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | |
| 4980 | template<typename Derived> |
| 4981 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4982 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4983 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4984 | } |
| 4985 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4986 | template<typename Derived> |
| 4987 | Sema::OwningExprResult |
| 4988 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4989 | CXXReinterpretCastExpr *E) { |
| 4990 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4993 | template<typename Derived> |
| 4994 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4995 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4996 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4998 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4999 | template<typename Derived> |
| 5000 | Sema::OwningExprResult |
| 5001 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5002 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5003 | TypeSourceInfo *OldT; |
| 5004 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5005 | { |
| 5006 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5007 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5008 | OldT = E->getTypeInfoAsWritten(); |
| 5009 | NewT = getDerived().TransformType(OldT); |
| 5010 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5011 | return SemaRef.ExprError(); |
| 5012 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5013 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5014 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5015 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5016 | if (SubExpr.isInvalid()) |
| 5017 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5019 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5020 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5021 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5022 | return SemaRef.Owned(E->Retain()); |
| 5023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | // FIXME: The end of the type's source range is wrong |
| 5025 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5026 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5027 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5029 | move(SubExpr), |
| 5030 | E->getRParenLoc()); |
| 5031 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5033 | template<typename Derived> |
| 5034 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5035 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5036 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5037 | TypeSourceInfo *TInfo |
| 5038 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5039 | if (!TInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5040 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5042 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5043 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5044 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5045 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5046 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5047 | E->getLocStart(), |
| 5048 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5049 | E->getLocEnd()); |
| 5050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5052 | // We don't know whether the expression is potentially evaluated until |
| 5053 | // after we perform semantic analysis, so the expression is potentially |
| 5054 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5057 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5058 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5059 | if (SubExpr.isInvalid()) |
| 5060 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5061 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5062 | if (!getDerived().AlwaysRebuild() && |
| 5063 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | return SemaRef.Owned(E->Retain()); |
| 5065 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5066 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5067 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5068 | move(SubExpr), |
| 5069 | E->getLocEnd()); |
| 5070 | } |
| 5071 | |
| 5072 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5074 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5075 | return SemaRef.Owned(E->Retain()); |
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>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5081 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5082 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5083 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5085 | template<typename Derived> |
| 5086 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5087 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5089 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5090 | QualType T = getDerived().TransformType(E->getType()); |
| 5091 | if (T.isNull()) |
| 5092 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5093 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5094 | if (!getDerived().AlwaysRebuild() && |
| 5095 | T == E->getType()) |
| 5096 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5098 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5099 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5100 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5101 | template<typename Derived> |
| 5102 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5103 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5104 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5105 | if (SubExpr.isInvalid()) |
| 5106 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5107 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5108 | if (!getDerived().AlwaysRebuild() && |
| 5109 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5110 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5111 | |
| 5112 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | template<typename Derived> |
| 5116 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5117 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5118 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5119 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5120 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | if (!Param) |
| 5122 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5123 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5124 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5125 | Param == E->getParam()) |
| 5126 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5127 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5128 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 | template<typename Derived> |
| 5132 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5133 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5134 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5135 | |
| 5136 | QualType T = getDerived().TransformType(E->getType()); |
| 5137 | if (T.isNull()) |
| 5138 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5139 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5140 | if (!getDerived().AlwaysRebuild() && |
| 5141 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5142 | return SemaRef.Owned(E->Retain()); |
| 5143 | |
| 5144 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5146 | T, |
| 5147 | E->getRParenLoc()); |
| 5148 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5150 | template<typename Derived> |
| 5151 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5152 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5153 | // Transform the type that we're allocating |
| 5154 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5155 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5156 | if (AllocType.isNull()) |
| 5157 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5159 | // Transform the size of the array we're allocating (if any). |
| 5160 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5161 | if (ArraySize.isInvalid()) |
| 5162 | return SemaRef.ExprError(); |
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 | // Transform the placement arguments (if any). |
| 5165 | bool ArgumentChanged = false; |
| 5166 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5167 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5168 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5169 | if (Arg.isInvalid()) |
| 5170 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5173 | PlacementArgs.push_back(Arg.take()); |
| 5174 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5176 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5178 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 5179 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5180 | if (Arg.isInvalid()) |
| 5181 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5183 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5184 | ConstructorArgs.push_back(Arg.take()); |
| 5185 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5187 | // Transform constructor, new operator, and delete operator. |
| 5188 | CXXConstructorDecl *Constructor = 0; |
| 5189 | if (E->getConstructor()) { |
| 5190 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5191 | getDerived().TransformDecl(E->getLocStart(), |
| 5192 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5193 | if (!Constructor) |
| 5194 | return SemaRef.ExprError(); |
| 5195 | } |
| 5196 | |
| 5197 | FunctionDecl *OperatorNew = 0; |
| 5198 | if (E->getOperatorNew()) { |
| 5199 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5200 | getDerived().TransformDecl(E->getLocStart(), |
| 5201 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5202 | if (!OperatorNew) |
| 5203 | return SemaRef.ExprError(); |
| 5204 | } |
| 5205 | |
| 5206 | FunctionDecl *OperatorDelete = 0; |
| 5207 | if (E->getOperatorDelete()) { |
| 5208 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5209 | getDerived().TransformDecl(E->getLocStart(), |
| 5210 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5211 | if (!OperatorDelete) |
| 5212 | return SemaRef.ExprError(); |
| 5213 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5215 | if (!getDerived().AlwaysRebuild() && |
| 5216 | AllocType == E->getAllocatedType() && |
| 5217 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5218 | Constructor == E->getConstructor() && |
| 5219 | OperatorNew == E->getOperatorNew() && |
| 5220 | OperatorDelete == E->getOperatorDelete() && |
| 5221 | !ArgumentChanged) { |
| 5222 | // Mark any declarations we need as referenced. |
| 5223 | // FIXME: instantiation-specific. |
| 5224 | if (Constructor) |
| 5225 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5226 | if (OperatorNew) |
| 5227 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5228 | if (OperatorDelete) |
| 5229 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5233 | if (!ArraySize.get()) { |
| 5234 | // If no array size was specified, but the new expression was |
| 5235 | // instantiated with an array type (e.g., "new T" where T is |
| 5236 | // instantiated with "int[4]"), extract the outer bound from the |
| 5237 | // array type as our array size. We do this with constant and |
| 5238 | // dependently-sized array types. |
| 5239 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5240 | if (!ArrayT) { |
| 5241 | // Do nothing |
| 5242 | } else if (const ConstantArrayType *ConsArrayT |
| 5243 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5244 | ArraySize |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5245 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5246 | ConsArrayT->getSize(), |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5247 | SemaRef.Context.getSizeType(), |
| 5248 | /*FIXME:*/E->getLocStart())); |
| 5249 | AllocType = ConsArrayT->getElementType(); |
| 5250 | } else if (const DependentSizedArrayType *DepArrayT |
| 5251 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5252 | if (DepArrayT->getSizeExpr()) { |
| 5253 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5254 | AllocType = DepArrayT->getElementType(); |
| 5255 | } |
| 5256 | } |
| 5257 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5259 | E->isGlobalNew(), |
| 5260 | /*FIXME:*/E->getLocStart(), |
| 5261 | move_arg(PlacementArgs), |
| 5262 | /*FIXME:*/E->getLocStart(), |
| 5263 | E->isParenTypeId(), |
| 5264 | AllocType, |
| 5265 | /*FIXME:*/E->getLocStart(), |
| 5266 | /*FIXME:*/SourceRange(), |
| 5267 | move(ArraySize), |
| 5268 | /*FIXME:*/E->getLocStart(), |
| 5269 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5270 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5271 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5272 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5273 | template<typename Derived> |
| 5274 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5275 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5276 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5277 | if (Operand.isInvalid()) |
| 5278 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5279 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5280 | // Transform the delete operator, if known. |
| 5281 | FunctionDecl *OperatorDelete = 0; |
| 5282 | if (E->getOperatorDelete()) { |
| 5283 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5284 | getDerived().TransformDecl(E->getLocStart(), |
| 5285 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5286 | if (!OperatorDelete) |
| 5287 | return SemaRef.ExprError(); |
| 5288 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5289 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5290 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5291 | Operand.get() == E->getArgument() && |
| 5292 | OperatorDelete == E->getOperatorDelete()) { |
| 5293 | // Mark any declarations we need as referenced. |
| 5294 | // FIXME: instantiation-specific. |
| 5295 | if (OperatorDelete) |
| 5296 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5297 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5298 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5299 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5300 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5301 | E->isGlobalDelete(), |
| 5302 | E->isArrayForm(), |
| 5303 | move(Operand)); |
| 5304 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5306 | template<typename Derived> |
| 5307 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5308 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5309 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5310 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5311 | if (Base.isInvalid()) |
| 5312 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5313 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5314 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5315 | bool MayBePseudoDestructor = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5316 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5317 | E->getOperatorLoc(), |
| 5318 | E->isArrow()? tok::arrow : tok::period, |
| 5319 | ObjectTypePtr, |
| 5320 | MayBePseudoDestructor); |
| 5321 | if (Base.isInvalid()) |
| 5322 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5323 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5324 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5325 | NestedNameSpecifier *Qualifier |
| 5326 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5327 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5328 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5329 | if (E->getQualifier() && !Qualifier) |
| 5330 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5332 | PseudoDestructorTypeStorage Destroyed; |
| 5333 | if (E->getDestroyedTypeInfo()) { |
| 5334 | TypeSourceInfo *DestroyedTypeInfo |
| 5335 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5336 | if (!DestroyedTypeInfo) |
| 5337 | return SemaRef.ExprError(); |
| 5338 | Destroyed = DestroyedTypeInfo; |
| 5339 | } else if (ObjectType->isDependentType()) { |
| 5340 | // We aren't likely to be able to resolve the identifier down to a type |
| 5341 | // now anyway, so just retain the identifier. |
| 5342 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5343 | E->getDestroyedTypeLoc()); |
| 5344 | } else { |
| 5345 | // Look for a destructor known with the given name. |
| 5346 | CXXScopeSpec SS; |
| 5347 | if (Qualifier) { |
| 5348 | SS.setScopeRep(Qualifier); |
| 5349 | SS.setRange(E->getQualifierRange()); |
| 5350 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5351 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5352 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5353 | *E->getDestroyedTypeIdentifier(), |
| 5354 | E->getDestroyedTypeLoc(), |
| 5355 | /*Scope=*/0, |
| 5356 | SS, ObjectTypePtr, |
| 5357 | false); |
| 5358 | if (!T) |
| 5359 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5361 | Destroyed |
| 5362 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5363 | E->getDestroyedTypeLoc()); |
| 5364 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5365 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5366 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5367 | if (E->getScopeTypeInfo()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5368 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5369 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5370 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5371 | return SemaRef.ExprError(); |
| 5372 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5373 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5374 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5375 | E->getOperatorLoc(), |
| 5376 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5377 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5378 | E->getQualifierRange(), |
| 5379 | ScopeTypeInfo, |
| 5380 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5381 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5382 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5383 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5385 | template<typename Derived> |
| 5386 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5387 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5388 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5389 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5390 | |
| 5391 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5392 | Sema::LookupOrdinaryName); |
| 5393 | |
| 5394 | // Transform all the decls. |
| 5395 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5396 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5397 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5398 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5399 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5400 | if (!InstD) { |
| 5401 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5402 | // This can happen because of dependent hiding. |
| 5403 | if (isa<UsingShadowDecl>(*I)) |
| 5404 | continue; |
| 5405 | else |
| 5406 | return SemaRef.ExprError(); |
| 5407 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5408 | |
| 5409 | // Expand using declarations. |
| 5410 | if (isa<UsingDecl>(InstD)) { |
| 5411 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5412 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5413 | E = UD->shadow_end(); I != E; ++I) |
| 5414 | R.addDecl(*I); |
| 5415 | continue; |
| 5416 | } |
| 5417 | |
| 5418 | R.addDecl(InstD); |
| 5419 | } |
| 5420 | |
| 5421 | // Resolve a kind, but don't do any further analysis. If it's |
| 5422 | // ambiguous, the callee needs to deal with it. |
| 5423 | R.resolveKind(); |
| 5424 | |
| 5425 | // Rebuild the nested-name qualifier, if present. |
| 5426 | CXXScopeSpec SS; |
| 5427 | NestedNameSpecifier *Qualifier = 0; |
| 5428 | if (Old->getQualifier()) { |
| 5429 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5430 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5431 | if (!Qualifier) |
| 5432 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5433 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5434 | SS.setScopeRep(Qualifier); |
| 5435 | SS.setRange(Old->getQualifierRange()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5436 | } |
| 5437 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5438 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5439 | CXXRecordDecl *NamingClass |
| 5440 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5441 | Old->getNameLoc(), |
| 5442 | Old->getNamingClass())); |
| 5443 | if (!NamingClass) |
| 5444 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5445 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5446 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | // If we have no template arguments, it's a normal declaration name. |
| 5450 | if (!Old->hasExplicitTemplateArgs()) |
| 5451 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5452 | |
| 5453 | // If we have template arguments, rebuild them, then rebuild the |
| 5454 | // templateid expression. |
| 5455 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5456 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5457 | TemplateArgumentLoc Loc; |
| 5458 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5459 | return SemaRef.ExprError(); |
| 5460 | TransArgs.addArgument(Loc); |
| 5461 | } |
| 5462 | |
| 5463 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5464 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5465 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5466 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5467 | template<typename Derived> |
| 5468 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5469 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5470 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5471 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5472 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5473 | if (T.isNull()) |
| 5474 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5475 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5476 | if (!getDerived().AlwaysRebuild() && |
| 5477 | T == E->getQueriedType()) |
| 5478 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5479 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5480 | // FIXME: Bad location information |
| 5481 | SourceLocation FakeLParenLoc |
| 5482 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5483 | |
| 5484 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5485 | E->getLocStart(), |
| 5486 | /*FIXME:*/FakeLParenLoc, |
| 5487 | T, |
| 5488 | E->getLocEnd()); |
| 5489 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5490 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5491 | template<typename Derived> |
| 5492 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5493 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5494 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5495 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5496 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5497 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5498 | if (!NNS) |
| 5499 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5500 | |
| 5501 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5502 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5503 | if (!Name) |
| 5504 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5505 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5506 | if (!E->hasExplicitTemplateArgs()) { |
| 5507 | if (!getDerived().AlwaysRebuild() && |
| 5508 | NNS == E->getQualifier() && |
| 5509 | Name == E->getDeclName()) |
| 5510 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5511 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5512 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5513 | E->getQualifierRange(), |
| 5514 | Name, E->getLocation(), |
| 5515 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5516 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5517 | |
| 5518 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5519 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5520 | TemplateArgumentLoc Loc; |
| 5521 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5522 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5523 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5524 | } |
| 5525 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5526 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5527 | E->getQualifierRange(), |
| 5528 | Name, E->getLocation(), |
| 5529 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | template<typename Derived> |
| 5533 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5534 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5535 | // CXXConstructExprs are always implicit, so when we have a |
| 5536 | // 1-argument construction we just transform that argument. |
| 5537 | if (E->getNumArgs() == 1 || |
| 5538 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5539 | return getDerived().TransformExpr(E->getArg(0)); |
| 5540 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5541 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5542 | |
| 5543 | QualType T = getDerived().TransformType(E->getType()); |
| 5544 | if (T.isNull()) |
| 5545 | return SemaRef.ExprError(); |
| 5546 | |
| 5547 | CXXConstructorDecl *Constructor |
| 5548 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5549 | getDerived().TransformDecl(E->getLocStart(), |
| 5550 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5551 | if (!Constructor) |
| 5552 | return SemaRef.ExprError(); |
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 | bool ArgumentChanged = false; |
| 5555 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5556 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5557 | ArgEnd = E->arg_end(); |
| 5558 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5559 | if (getDerived().DropCallArgument(*Arg)) { |
| 5560 | ArgumentChanged = true; |
| 5561 | break; |
| 5562 | } |
| 5563 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5564 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5565 | if (TransArg.isInvalid()) |
| 5566 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5569 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5570 | } |
| 5571 | |
| 5572 | if (!getDerived().AlwaysRebuild() && |
| 5573 | T == E->getType() && |
| 5574 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5575 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5576 | // Mark the constructor as referenced. |
| 5577 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5578 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5579 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5581 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5582 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5583 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5584 | move_arg(Args)); |
| 5585 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5586 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5587 | /// \brief Transform a C++ temporary-binding expression. |
| 5588 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5589 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5590 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | template<typename Derived> |
| 5592 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5593 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5594 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5596 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5597 | /// \brief Transform a C++ reference-binding expression. |
| 5598 | /// |
| 5599 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5600 | /// transform the subexpression and return that. |
| 5601 | template<typename Derived> |
| 5602 | Sema::OwningExprResult |
| 5603 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5604 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5605 | } |
| 5606 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5608 | /// be destroyed after the expression is evaluated. |
| 5609 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5610 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5611 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5612 | template<typename Derived> |
| 5613 | Sema::OwningExprResult |
| 5614 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5615 | CXXExprWithTemporaries *E) { |
| 5616 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5619 | template<typename Derived> |
| 5620 | Sema::OwningExprResult |
| 5621 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5622 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5624 | QualType T = getDerived().TransformType(E->getType()); |
| 5625 | if (T.isNull()) |
| 5626 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5627 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5628 | CXXConstructorDecl *Constructor |
| 5629 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5630 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5631 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5632 | if (!Constructor) |
| 5633 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5635 | bool ArgumentChanged = false; |
| 5636 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5637 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5638 | for (CXXTemporaryObjectExpr::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 | 9bc6b7f | 2010-03-02 17:18:33 +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((Expr *)TransArg.release()); |
| 5652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | if (!getDerived().AlwaysRebuild() && |
| 5655 | T == E->getType() && |
| 5656 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5657 | !ArgumentChanged) { |
| 5658 | // FIXME: Instantiation-specific |
| 5659 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5660 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5663 | // FIXME: Bogus location information |
| 5664 | SourceLocation CommaLoc; |
| 5665 | if (Args.size() > 1) { |
| 5666 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5667 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5668 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5669 | } |
| 5670 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5671 | T, |
| 5672 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5673 | move_arg(Args), |
| 5674 | &CommaLoc, |
| 5675 | E->getLocEnd()); |
| 5676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5677 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5678 | template<typename Derived> |
| 5679 | Sema::OwningExprResult |
| 5680 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5681 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5682 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5683 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5684 | if (T.isNull()) |
| 5685 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5687 | bool ArgumentChanged = false; |
| 5688 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5689 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5690 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5691 | ArgEnd = E->arg_end(); |
| 5692 | Arg != ArgEnd; ++Arg) { |
| 5693 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5694 | if (TransArg.isInvalid()) |
| 5695 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5696 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5697 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5698 | FakeCommaLocs.push_back( |
| 5699 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5700 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5701 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5703 | if (!getDerived().AlwaysRebuild() && |
| 5704 | T == E->getTypeAsWritten() && |
| 5705 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5706 | return SemaRef.Owned(E->Retain()); |
| 5707 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5708 | // FIXME: we're faking the locations of the commas |
| 5709 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5710 | T, |
| 5711 | E->getLParenLoc(), |
| 5712 | move_arg(Args), |
| 5713 | FakeCommaLocs.data(), |
| 5714 | E->getRParenLoc()); |
| 5715 | } |
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 | template<typename Derived> |
| 5718 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5719 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5720 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5721 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5722 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5723 | Expr *OldBase; |
| 5724 | QualType BaseType; |
| 5725 | QualType ObjectType; |
| 5726 | if (!E->isImplicitAccess()) { |
| 5727 | OldBase = E->getBase(); |
| 5728 | Base = getDerived().TransformExpr(OldBase); |
| 5729 | if (Base.isInvalid()) |
| 5730 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5731 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5732 | // Start the member reference and compute the object's type. |
| 5733 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5734 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5735 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5736 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5737 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5738 | ObjectTy, |
| 5739 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5740 | if (Base.isInvalid()) |
| 5741 | return SemaRef.ExprError(); |
| 5742 | |
| 5743 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5744 | BaseType = ((Expr*) Base.get())->getType(); |
| 5745 | } else { |
| 5746 | OldBase = 0; |
| 5747 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5748 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5749 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5750 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5751 | // Transform the first part of the nested-name-specifier that qualifies |
| 5752 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5753 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5754 | = getDerived().TransformFirstQualifierInScope( |
| 5755 | E->getFirstQualifierFoundInScope(), |
| 5756 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5757 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5758 | NestedNameSpecifier *Qualifier = 0; |
| 5759 | if (E->getQualifier()) { |
| 5760 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5761 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5762 | ObjectType, |
| 5763 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5764 | if (!Qualifier) |
| 5765 | return SemaRef.ExprError(); |
| 5766 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5767 | |
| 5768 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5769 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5770 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5771 | if (!Name) |
| 5772 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5773 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5774 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5775 | // This is a reference to a member without an explicitly-specified |
| 5776 | // template argument list. Optimize for this common case. |
| 5777 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5778 | Base.get() == OldBase && |
| 5779 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5780 | Qualifier == E->getQualifier() && |
| 5781 | Name == E->getMember() && |
| 5782 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5783 | return SemaRef.Owned(E->Retain()); |
| 5784 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5785 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5786 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5787 | E->isArrow(), |
| 5788 | E->getOperatorLoc(), |
| 5789 | Qualifier, |
| 5790 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5791 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5792 | Name, |
| 5793 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5794 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5795 | } |
| 5796 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5797 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5798 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5799 | TemplateArgumentLoc Loc; |
| 5800 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5801 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5802 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5804 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5805 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5806 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5807 | E->isArrow(), |
| 5808 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5809 | Qualifier, |
| 5810 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5811 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5812 | Name, |
| 5813 | E->getMemberLoc(), |
| 5814 | &TransArgs); |
| 5815 | } |
| 5816 | |
| 5817 | template<typename Derived> |
| 5818 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5819 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5820 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5821 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5822 | QualType BaseType; |
| 5823 | if (!Old->isImplicitAccess()) { |
| 5824 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5825 | if (Base.isInvalid()) |
| 5826 | return SemaRef.ExprError(); |
| 5827 | BaseType = ((Expr*) Base.get())->getType(); |
| 5828 | } else { |
| 5829 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5830 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5831 | |
| 5832 | NestedNameSpecifier *Qualifier = 0; |
| 5833 | if (Old->getQualifier()) { |
| 5834 | Qualifier |
| 5835 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5836 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5837 | if (Qualifier == 0) |
| 5838 | return SemaRef.ExprError(); |
| 5839 | } |
| 5840 | |
| 5841 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5842 | Sema::LookupOrdinaryName); |
| 5843 | |
| 5844 | // Transform all the decls. |
| 5845 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5846 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5847 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5848 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5849 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5850 | if (!InstD) { |
| 5851 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5852 | // This can happen because of dependent hiding. |
| 5853 | if (isa<UsingShadowDecl>(*I)) |
| 5854 | continue; |
| 5855 | else |
| 5856 | return SemaRef.ExprError(); |
| 5857 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5858 | |
| 5859 | // Expand using declarations. |
| 5860 | if (isa<UsingDecl>(InstD)) { |
| 5861 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5862 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5863 | E = UD->shadow_end(); I != E; ++I) |
| 5864 | R.addDecl(*I); |
| 5865 | continue; |
| 5866 | } |
| 5867 | |
| 5868 | R.addDecl(InstD); |
| 5869 | } |
| 5870 | |
| 5871 | R.resolveKind(); |
| 5872 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5873 | // Determine the naming class. |
| 5874 | if (!Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5875 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5876 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5877 | Old->getMemberLoc(), |
| 5878 | Old->getNamingClass())); |
| 5879 | if (!NamingClass) |
| 5880 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5881 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5882 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5883 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5884 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5885 | TemplateArgumentListInfo TransArgs; |
| 5886 | if (Old->hasExplicitTemplateArgs()) { |
| 5887 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5888 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5889 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5890 | TemplateArgumentLoc Loc; |
| 5891 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5892 | Loc)) |
| 5893 | return SemaRef.ExprError(); |
| 5894 | TransArgs.addArgument(Loc); |
| 5895 | } |
| 5896 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5897 | |
| 5898 | // FIXME: to do this check properly, we will need to preserve the |
| 5899 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5900 | // base (and therefore couldn't do the check) and a |
| 5901 | // nested-name-qualifier (and therefore could do the lookup). |
| 5902 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5903 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5904 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5905 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5906 | Old->getOperatorLoc(), |
| 5907 | Old->isArrow(), |
| 5908 | Qualifier, |
| 5909 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5910 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5911 | R, |
| 5912 | (Old->hasExplicitTemplateArgs() |
| 5913 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | template<typename Derived> |
| 5917 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5918 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5919 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5920 | } |
| 5921 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5922 | template<typename Derived> |
| 5923 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5924 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5925 | TypeSourceInfo *EncodedTypeInfo |
| 5926 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5927 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5928 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5929 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5930 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5931 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5932 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5933 | |
| 5934 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5935 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5936 | E->getRParenLoc()); |
| 5937 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5939 | template<typename Derived> |
| 5940 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5941 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5942 | // Transform arguments. |
| 5943 | bool ArgChanged = false; |
| 5944 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5945 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5946 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5947 | if (Arg.isInvalid()) |
| 5948 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5949 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5950 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5951 | Args.push_back(Arg.takeAs<Expr>()); |
| 5952 | } |
| 5953 | |
| 5954 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5955 | // Class message: transform the receiver type. |
| 5956 | TypeSourceInfo *ReceiverTypeInfo |
| 5957 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5958 | if (!ReceiverTypeInfo) |
| 5959 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5960 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5961 | // If nothing changed, just retain the existing message send. |
| 5962 | if (!getDerived().AlwaysRebuild() && |
| 5963 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5964 | return SemaRef.Owned(E->Retain()); |
| 5965 | |
| 5966 | // Build a new class message send. |
| 5967 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5968 | E->getSelector(), |
| 5969 | E->getMethodDecl(), |
| 5970 | E->getLeftLoc(), |
| 5971 | move_arg(Args), |
| 5972 | E->getRightLoc()); |
| 5973 | } |
| 5974 | |
| 5975 | // Instance message: transform the receiver |
| 5976 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5977 | "Only class and instance messages may be instantiated"); |
| 5978 | OwningExprResult Receiver |
| 5979 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5980 | if (Receiver.isInvalid()) |
| 5981 | return SemaRef.ExprError(); |
| 5982 | |
| 5983 | // If nothing changed, just retain the existing message send. |
| 5984 | if (!getDerived().AlwaysRebuild() && |
| 5985 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5986 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5987 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5988 | // Build a new instance message send. |
| 5989 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5990 | E->getSelector(), |
| 5991 | E->getMethodDecl(), |
| 5992 | E->getLeftLoc(), |
| 5993 | move_arg(Args), |
| 5994 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5995 | } |
| 5996 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5997 | template<typename Derived> |
| 5998 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5999 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6000 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6001 | } |
| 6002 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6003 | template<typename Derived> |
| 6004 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6005 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6006 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6007 | } |
| 6008 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6009 | template<typename Derived> |
| 6010 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6011 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6012 | // Transform the base expression. |
| 6013 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6014 | if (Base.isInvalid()) |
| 6015 | return SemaRef.ExprError(); |
| 6016 | |
| 6017 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6018 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6019 | // If nothing changed, just retain the existing expression. |
| 6020 | if (!getDerived().AlwaysRebuild() && |
| 6021 | Base.get() == E->getBase()) |
| 6022 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6023 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6024 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6025 | E->getLocation(), |
| 6026 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6027 | } |
| 6028 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6029 | template<typename Derived> |
| 6030 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6031 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6032 | // Transform the base expression. |
| 6033 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6034 | if (Base.isInvalid()) |
| 6035 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6036 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6037 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6038 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6039 | // If nothing changed, just retain the existing expression. |
| 6040 | if (!getDerived().AlwaysRebuild() && |
| 6041 | Base.get() == E->getBase()) |
| 6042 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6043 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6044 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6045 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6046 | } |
| 6047 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6048 | template<typename Derived> |
| 6049 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6050 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6051 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6052 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6053 | // dependent parts. Just retain the existing declaration. |
| 6054 | if (E->getInterfaceDecl()) |
| 6055 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6056 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6057 | // Transform the base expression. |
| 6058 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6059 | if (Base.isInvalid()) |
| 6060 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6061 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6062 | // 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] | 6063 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6064 | // If nothing changed, just retain the existing expression. |
| 6065 | if (!getDerived().AlwaysRebuild() && |
| 6066 | Base.get() == E->getBase()) |
| 6067 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6068 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6069 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6070 | E->getGetterMethod(), |
| 6071 | E->getType(), |
| 6072 | E->getSetterMethod(), |
| 6073 | E->getLocation(), |
| 6074 | move(Base)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6075 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6076 | } |
| 6077 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6078 | template<typename Derived> |
| 6079 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6080 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6081 | // Can never occur in a dependent context. |
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>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6088 | // Transform the base expression. |
| 6089 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6090 | if (Base.isInvalid()) |
| 6091 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6092 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6093 | // If nothing changed, just retain the existing expression. |
| 6094 | if (!getDerived().AlwaysRebuild() && |
| 6095 | Base.get() == E->getBase()) |
| 6096 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6097 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6098 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6099 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6102 | template<typename Derived> |
| 6103 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6104 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6105 | bool ArgumentChanged = false; |
| 6106 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6107 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6108 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6109 | if (SubExpr.isInvalid()) |
| 6110 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6112 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6113 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6115 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6116 | if (!getDerived().AlwaysRebuild() && |
| 6117 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6118 | return SemaRef.Owned(E->Retain()); |
| 6119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6121 | move_arg(SubExprs), |
| 6122 | E->getRParenLoc()); |
| 6123 | } |
| 6124 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6125 | template<typename Derived> |
| 6126 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6127 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6128 | // FIXME: Implement this! |
| 6129 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6130 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6131 | } |
| 6132 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6133 | template<typename Derived> |
| 6134 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6135 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6136 | // FIXME: Implement this! |
| 6137 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6138 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6141 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6142 | // Type reconstruction |
| 6143 | //===----------------------------------------------------------------------===// |
| 6144 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6145 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6146 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6147 | SourceLocation Star) { |
| 6148 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6149 | getDerived().getBaseEntity()); |
| 6150 | } |
| 6151 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6152 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6153 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6154 | SourceLocation Star) { |
| 6155 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6156 | getDerived().getBaseEntity()); |
| 6157 | } |
| 6158 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6159 | template<typename Derived> |
| 6160 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6161 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6162 | bool WrittenAsLValue, |
| 6163 | SourceLocation Sigil) { |
| 6164 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 6165 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6169 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6170 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6171 | QualType ClassType, |
| 6172 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 6173 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6174 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6178 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6179 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6180 | ArrayType::ArraySizeModifier SizeMod, |
| 6181 | const llvm::APInt *Size, |
| 6182 | Expr *SizeExpr, |
| 6183 | unsigned IndexTypeQuals, |
| 6184 | SourceRange BracketsRange) { |
| 6185 | if (SizeExpr || !Size) |
| 6186 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6187 | IndexTypeQuals, BracketsRange, |
| 6188 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6189 | |
| 6190 | QualType Types[] = { |
| 6191 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6192 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6193 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6194 | }; |
| 6195 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6196 | QualType SizeType; |
| 6197 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6198 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6199 | SizeType = Types[I]; |
| 6200 | break; |
| 6201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6202 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6203 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6204 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6205 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6206 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6208 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6209 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6210 | QualType |
| 6211 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6212 | ArrayType::ArraySizeModifier SizeMod, |
| 6213 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6214 | unsigned IndexTypeQuals, |
| 6215 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6216 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6217 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6221 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6222 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6223 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6224 | unsigned IndexTypeQuals, |
| 6225 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6226 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6227 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6229 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6230 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6231 | QualType |
| 6232 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6233 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6234 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6235 | unsigned IndexTypeQuals, |
| 6236 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6237 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6238 | SizeExpr.takeAs<Expr>(), |
| 6239 | IndexTypeQuals, BracketsRange); |
| 6240 | } |
| 6241 | |
| 6242 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6243 | QualType |
| 6244 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6245 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6246 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6247 | unsigned IndexTypeQuals, |
| 6248 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6249 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6250 | SizeExpr.takeAs<Expr>(), |
| 6251 | IndexTypeQuals, BracketsRange); |
| 6252 | } |
| 6253 | |
| 6254 | template<typename Derived> |
| 6255 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6256 | unsigned NumElements, |
| 6257 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6258 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6259 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 6260 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6262 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6263 | template<typename Derived> |
| 6264 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6265 | unsigned NumElements, |
| 6266 | SourceLocation AttributeLoc) { |
| 6267 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6268 | NumElements, true); |
| 6269 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6270 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6271 | AttributeLoc); |
| 6272 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6273 | AttributeLoc); |
| 6274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6275 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6276 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6277 | QualType |
| 6278 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6279 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6280 | SourceLocation AttributeLoc) { |
| 6281 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6282 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6283 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6284 | template<typename Derived> |
| 6285 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6286 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6287 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6288 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6289 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6290 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6291 | Quals, |
| 6292 | getDerived().getBaseLocation(), |
| 6293 | getDerived().getBaseEntity()); |
| 6294 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6295 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6296 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6297 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6298 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6299 | } |
| 6300 | |
| 6301 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6302 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6303 | assert(D && "no decl found"); |
| 6304 | if (D->isInvalidDecl()) return QualType(); |
| 6305 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6306 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6307 | TypeDecl *Ty; |
| 6308 | if (isa<UsingDecl>(D)) { |
| 6309 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6310 | assert(Using->isTypeName() && |
| 6311 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6312 | |
| 6313 | // A valid resolved using typename decl points to exactly one type decl. |
| 6314 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6315 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6316 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6317 | } else { |
| 6318 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6319 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6320 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6321 | } |
| 6322 | |
| 6323 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6324 | } |
| 6325 | |
| 6326 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6327 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6328 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6329 | } |
| 6330 | |
| 6331 | template<typename Derived> |
| 6332 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6333 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6334 | } |
| 6335 | |
| 6336 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6337 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6338 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6339 | } |
| 6340 | |
| 6341 | template<typename Derived> |
| 6342 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6343 | TemplateName Template, |
| 6344 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6345 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6346 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6348 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6349 | template<typename Derived> |
| 6350 | NestedNameSpecifier * |
| 6351 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6352 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6353 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6354 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6355 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6356 | CXXScopeSpec SS; |
| 6357 | // FIXME: The source location information is all wrong. |
| 6358 | SS.setRange(Range); |
| 6359 | SS.setScopeRep(Prefix); |
| 6360 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6361 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6362 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6363 | ObjectType, |
| 6364 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6365 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | template<typename Derived> |
| 6369 | NestedNameSpecifier * |
| 6370 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6371 | SourceRange Range, |
| 6372 | NamespaceDecl *NS) { |
| 6373 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6374 | } |
| 6375 | |
| 6376 | template<typename Derived> |
| 6377 | NestedNameSpecifier * |
| 6378 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6379 | SourceRange Range, |
| 6380 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6381 | QualType T) { |
| 6382 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6383 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6384 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6385 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6386 | T.getTypePtr()); |
| 6387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6388 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6389 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6390 | return 0; |
| 6391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6392 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6393 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6394 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6395 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6396 | bool TemplateKW, |
| 6397 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6398 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6399 | Template); |
| 6400 | } |
| 6401 | |
| 6402 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6403 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6404 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6405 | const IdentifierInfo &II, |
| 6406 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6407 | CXXScopeSpec SS; |
| 6408 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6409 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6410 | UnqualifiedId Name; |
| 6411 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6412 | return getSema().ActOnDependentTemplateName( |
| 6413 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6414 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6415 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6416 | ObjectType.getAsOpaquePtr(), |
| 6417 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6418 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6419 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6420 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6421 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6422 | TemplateName |
| 6423 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6424 | OverloadedOperatorKind Operator, |
| 6425 | QualType ObjectType) { |
| 6426 | CXXScopeSpec SS; |
| 6427 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6428 | SS.setScopeRep(Qualifier); |
| 6429 | UnqualifiedId Name; |
| 6430 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6431 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6432 | Operator, SymbolLocations); |
| 6433 | return getSema().ActOnDependentTemplateName( |
| 6434 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6435 | SS, |
| 6436 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6437 | ObjectType.getAsOpaquePtr(), |
| 6438 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6439 | .template getAsVal<TemplateName>(); |
| 6440 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6441 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6442 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6443 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6444 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6445 | SourceLocation OpLoc, |
| 6446 | ExprArg Callee, |
| 6447 | ExprArg First, |
| 6448 | ExprArg Second) { |
| 6449 | Expr *FirstExpr = (Expr *)First.get(); |
| 6450 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6451 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6452 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6453 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6454 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6455 | if (Op == OO_Subscript) { |
| 6456 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6457 | !SecondExpr->getType()->isOverloadableType()) |
| 6458 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6459 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6460 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6461 | } else if (Op == OO_Arrow) { |
| 6462 | // -> is never a builtin operation. |
| 6463 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6464 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6465 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6466 | // The argument is not of overloadable type, so try to create a |
| 6467 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6468 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6471 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6472 | } |
| 6473 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6474 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6475 | !SecondExpr->getType()->isOverloadableType()) { |
| 6476 | // Neither of the arguments is an overloadable type, so try to |
| 6477 | // create a built-in binary operation. |
| 6478 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6479 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6480 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6481 | if (Result.isInvalid()) |
| 6482 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6483 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6484 | First.release(); |
| 6485 | Second.release(); |
| 6486 | return move(Result); |
| 6487 | } |
| 6488 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6489 | |
| 6490 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6491 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6492 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6494 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6495 | assert(ULE->requiresADL()); |
| 6496 | |
| 6497 | // FIXME: Do we have to check |
| 6498 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6499 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6500 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6501 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6503 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6504 | // Add any functions found via argument-dependent lookup. |
| 6505 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6506 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6507 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6508 | // Create the overloaded operator invocation for unary operators. |
| 6509 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6510 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6511 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6512 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6513 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6515 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6516 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6517 | OpLoc, |
| 6518 | move(First), |
| 6519 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6520 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6521 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6522 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6523 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6524 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6525 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6526 | if (Result.isInvalid()) |
| 6527 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6529 | First.release(); |
| 6530 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6531 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6532 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6533 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6534 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6535 | Sema::OwningExprResult |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6536 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6537 | SourceLocation OperatorLoc, |
| 6538 | bool isArrow, |
| 6539 | NestedNameSpecifier *Qualifier, |
| 6540 | SourceRange QualifierRange, |
| 6541 | TypeSourceInfo *ScopeType, |
| 6542 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6543 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6544 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6545 | CXXScopeSpec SS; |
| 6546 | if (Qualifier) { |
| 6547 | SS.setRange(QualifierRange); |
| 6548 | SS.setScopeRep(Qualifier); |
| 6549 | } |
| 6550 | |
| 6551 | Expr *BaseE = (Expr *)Base.get(); |
| 6552 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6553 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6554 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6555 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6556 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6557 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6558 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6559 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6560 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6561 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6562 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6563 | /*FIXME?*/true); |
| 6564 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6565 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6566 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6567 | DeclarationName Name |
| 6568 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6569 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6570 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6571 | // FIXME: the ScopeType should be tacked onto SS. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6572 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6573 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6574 | OperatorLoc, isArrow, |
| 6575 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6576 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6577 | /*TemplateArgs*/ 0); |
| 6578 | } |
| 6579 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6580 | } // end namespace clang |
| 6581 | |
| 6582 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |