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 | |
| 495 | /// \brief Build a new elaborated type. |
| 496 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 497 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 498 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
| 500 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | /// |
| 502 | /// By default, performs semantic analysis when building the typeof type. |
| 503 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 504 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, builds a new TypeOfType with the given underlying type. |
| 509 | QualType RebuildTypeOfType(QualType Underlying); |
| 510 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// |
| 513 | /// By default, performs semantic analysis when building the decltype type. |
| 514 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 515 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 517 | /// \brief Build a new template specialization type. |
| 518 | /// |
| 519 | /// By default, performs semantic analysis when building the template |
| 520 | /// specialization type. Subclasses may override this routine to provide |
| 521 | /// different behavior. |
| 522 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 523 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 524 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | /// \brief Build a new qualified name type. |
| 527 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | /// By default, builds a new QualifiedNameType type from the |
| 529 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | /// this routine to provide different behavior. |
| 531 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 532 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | |
| 535 | /// \brief Build a new typename type that refers to a template-id. |
| 536 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 537 | /// By default, builds a new DependentNameType type from the |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 538 | /// nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 541 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 542 | NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 543 | if (NNS->isDependent()) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 544 | // If the name is still dependent, just build a new dependent name type. |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 545 | CXXScopeSpec SS; |
| 546 | SS.setScopeRep(NNS); |
| 547 | if (!SemaRef.computeDeclContext(SS)) |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 548 | return SemaRef.Context.getDependentNameType(Keyword, NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 549 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 550 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 552 | // FIXME: Handle elaborated-type-specifiers separately. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 553 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 555 | |
| 556 | /// \brief Build a new typename type that refers to an identifier. |
| 557 | /// |
| 558 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 560 | /// different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 561 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 562 | NestedNameSpecifier *NNS, |
| 563 | const IdentifierInfo *Id, |
| 564 | SourceRange SR) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 565 | CXXScopeSpec SS; |
| 566 | SS.setScopeRep(NNS); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 567 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 568 | if (NNS->isDependent()) { |
| 569 | // If the name is still dependent, just build a new dependent name type. |
| 570 | if (!SemaRef.computeDeclContext(SS)) |
| 571 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 572 | } |
| 573 | |
| 574 | TagDecl::TagKind Kind = TagDecl::TK_enum; |
| 575 | switch (Keyword) { |
| 576 | case ETK_None: |
Douglas Gregor | bbdf20a | 2010-04-24 15:35:55 +0000 | [diff] [blame] | 577 | // Fall through. |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 578 | case ETK_Typename: |
Douglas Gregor | bbdf20a | 2010-04-24 15:35:55 +0000 | [diff] [blame] | 579 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 580 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 581 | case ETK_Class: Kind = TagDecl::TK_class; break; |
| 582 | case ETK_Struct: Kind = TagDecl::TK_struct; break; |
| 583 | case ETK_Union: Kind = TagDecl::TK_union; break; |
| 584 | case ETK_Enum: Kind = TagDecl::TK_enum; break; |
| 585 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 586 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 587 | // We had a dependent elaborated-type-specifier that as been transformed |
| 588 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 589 | // referring to. |
| 590 | LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName); |
| 591 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 592 | if (!DC) |
| 593 | return QualType(); |
| 594 | |
| 595 | TagDecl *Tag = 0; |
| 596 | SemaRef.LookupQualifiedName(Result, DC); |
| 597 | switch (Result.getResultKind()) { |
| 598 | case LookupResult::NotFound: |
| 599 | case LookupResult::NotFoundInCurrentInstantiation: |
| 600 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 602 | case LookupResult::Found: |
| 603 | Tag = Result.getAsSingle<TagDecl>(); |
| 604 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 606 | case LookupResult::FoundOverloaded: |
| 607 | case LookupResult::FoundUnresolvedValue: |
| 608 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 609 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 611 | case LookupResult::Ambiguous: |
| 612 | // Let the LookupResult structure handle ambiguities. |
| 613 | return QualType(); |
| 614 | } |
| 615 | |
| 616 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 617 | // FIXME: Would be nice to highlight just the source range. |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 618 | SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 619 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 620 | return QualType(); |
| 621 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 622 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 623 | // FIXME: Terrible location information |
| 624 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) { |
| 625 | SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id; |
| 626 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 627 | return QualType(); |
| 628 | } |
| 629 | |
| 630 | // Build the elaborated-type-specifier type. |
| 631 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 632 | T = SemaRef.Context.getQualifiedNameType(NNS, T); |
| 633 | return SemaRef.Context.getElaboratedType(T, Kind); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 636 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 637 | /// identifier that names the next step in the nested-name-specifier. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis when building the new |
| 640 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 641 | /// different behavior. |
| 642 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 643 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 644 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 645 | QualType ObjectType, |
| 646 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 647 | |
| 648 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 649 | /// namespace named in the next step in the nested-name-specifier. |
| 650 | /// |
| 651 | /// By default, performs semantic analysis when building the new |
| 652 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 653 | /// different behavior. |
| 654 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 655 | SourceRange Range, |
| 656 | NamespaceDecl *NS); |
| 657 | |
| 658 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 659 | /// type named in the next step in the nested-name-specifier. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis when building the new |
| 662 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 663 | /// different behavior. |
| 664 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 665 | SourceRange Range, |
| 666 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 667 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 668 | |
| 669 | /// \brief Build a new template name given a nested name specifier, a flag |
| 670 | /// indicating whether the "template" keyword was provided, and the template |
| 671 | /// that the template name refers to. |
| 672 | /// |
| 673 | /// By default, builds the new template name directly. Subclasses may override |
| 674 | /// this routine to provide different behavior. |
| 675 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 676 | bool TemplateKW, |
| 677 | TemplateDecl *Template); |
| 678 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 679 | /// \brief Build a new template name given a nested name specifier and the |
| 680 | /// name that is referred to as a template. |
| 681 | /// |
| 682 | /// By default, performs semantic analysis to determine whether the name can |
| 683 | /// be resolved to a specific template, then builds the appropriate kind of |
| 684 | /// template name. Subclasses may override this routine to provide different |
| 685 | /// behavior. |
| 686 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 687 | const IdentifierInfo &II, |
| 688 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 690 | /// \brief Build a new template name given a nested name specifier and the |
| 691 | /// overloaded operator name that is referred to as a template. |
| 692 | /// |
| 693 | /// By default, performs semantic analysis to determine whether the name can |
| 694 | /// be resolved to a specific template, then builds the appropriate kind of |
| 695 | /// template name. Subclasses may override this routine to provide different |
| 696 | /// behavior. |
| 697 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 698 | OverloadedOperatorKind Operator, |
| 699 | QualType ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 700 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 701 | /// \brief Build a new compound statement. |
| 702 | /// |
| 703 | /// By default, performs semantic analysis to build the new statement. |
| 704 | /// Subclasses may override this routine to provide different behavior. |
| 705 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 706 | MultiStmtArg Statements, |
| 707 | SourceLocation RBraceLoc, |
| 708 | bool IsStmtExpr) { |
| 709 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 710 | IsStmtExpr); |
| 711 | } |
| 712 | |
| 713 | /// \brief Build a new case statement. |
| 714 | /// |
| 715 | /// By default, performs semantic analysis to build the new statement. |
| 716 | /// Subclasses may override this routine to provide different behavior. |
| 717 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 718 | ExprArg LHS, |
| 719 | SourceLocation EllipsisLoc, |
| 720 | ExprArg RHS, |
| 721 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 723 | ColonLoc); |
| 724 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | /// \brief Attach the body to a new case statement. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis to build the new statement. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
| 730 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 731 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 732 | return move(S); |
| 733 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | /// \brief Build a new default statement. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis to build the new statement. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 740 | SourceLocation ColonLoc, |
| 741 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 743 | /*CurScope=*/0); |
| 744 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 746 | /// \brief Build a new label statement. |
| 747 | /// |
| 748 | /// By default, performs semantic analysis to build the new statement. |
| 749 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 751 | IdentifierInfo *Id, |
| 752 | SourceLocation ColonLoc, |
| 753 | StmtArg SubStmt) { |
| 754 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 757 | /// \brief Build a new "if" statement. |
| 758 | /// |
| 759 | /// By default, performs semantic analysis to build the new statement. |
| 760 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 761 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::ExprArg Cond, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 762 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 763 | SourceLocation ElseLoc, StmtArg Else) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 764 | if (Cond.get()) { |
| 765 | // Convert the condition to a boolean value. |
| 766 | Cond = getSema().ActOnBooleanCondition(0, IfLoc, move(Cond)); |
| 767 | if (Cond.isInvalid()) |
| 768 | return getSema().StmtError(); |
| 769 | } |
| 770 | |
| 771 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 772 | return getSema().ActOnIfStmt(IfLoc, FullCond, DeclPtrTy::make(CondVar), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 773 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 774 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | /// \brief Start building a new switch statement. |
| 777 | /// |
| 778 | /// By default, performs semantic analysis to build the new statement. |
| 779 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 780 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 781 | Sema::ExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 782 | VarDecl *CondVar) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 783 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
| 784 | DeclPtrTy::make(CondVar)); |
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 Attach the body to the switch statement. |
| 788 | /// |
| 789 | /// By default, performs semantic analysis to build the new statement. |
| 790 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 792 | StmtArg Switch, StmtArg Body) { |
| 793 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 794 | move(Body)); |
| 795 | } |
| 796 | |
| 797 | /// \brief Build a new while statement. |
| 798 | /// |
| 799 | /// By default, performs semantic analysis to build the new statement. |
| 800 | /// Subclasses may override this routine to provide different behavior. |
| 801 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 802 | Sema::ExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 803 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 804 | StmtArg Body) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 805 | if (Cond.get()) { |
| 806 | // Convert the condition to a boolean value. |
| 807 | Cond = getSema().ActOnBooleanCondition(0, WhileLoc, move(Cond)); |
| 808 | if (Cond.isInvalid()) |
| 809 | return getSema().StmtError(); |
| 810 | } |
| 811 | |
| 812 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 813 | return getSema().ActOnWhileStmt(WhileLoc, FullCond, |
| 814 | DeclPtrTy::make(CondVar), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 815 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 817 | /// \brief Build a new do-while statement. |
| 818 | /// |
| 819 | /// By default, performs semantic analysis to build the new statement. |
| 820 | /// Subclasses may override this routine to provide different behavior. |
| 821 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 822 | SourceLocation WhileLoc, |
| 823 | SourceLocation LParenLoc, |
| 824 | ExprArg Cond, |
| 825 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | move(Cond), RParenLoc); |
| 828 | } |
| 829 | |
| 830 | /// \brief Build a new for statement. |
| 831 | /// |
| 832 | /// By default, performs semantic analysis to build the new statement. |
| 833 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 834 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 835 | SourceLocation LParenLoc, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 836 | StmtArg Init, Sema::ExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 837 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 838 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 839 | if (Cond.get()) { |
| 840 | // Convert the condition to a boolean value. |
| 841 | Cond = getSema().ActOnBooleanCondition(0, ForLoc, move(Cond)); |
| 842 | if (Cond.isInvalid()) |
| 843 | return getSema().StmtError(); |
| 844 | } |
| 845 | |
| 846 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 847 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), FullCond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 848 | DeclPtrTy::make(CondVar), |
| 849 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 851 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 852 | /// \brief Build a new goto statement. |
| 853 | /// |
| 854 | /// By default, performs semantic analysis to build the new statement. |
| 855 | /// Subclasses may override this routine to provide different behavior. |
| 856 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 857 | SourceLocation LabelLoc, |
| 858 | LabelStmt *Label) { |
| 859 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 860 | } |
| 861 | |
| 862 | /// \brief Build a new indirect goto statement. |
| 863 | /// |
| 864 | /// By default, performs semantic analysis to build the new statement. |
| 865 | /// Subclasses may override this routine to provide different behavior. |
| 866 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 867 | SourceLocation StarLoc, |
| 868 | ExprArg Target) { |
| 869 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 872 | /// \brief Build a new return statement. |
| 873 | /// |
| 874 | /// By default, performs semantic analysis to build the new statement. |
| 875 | /// Subclasses may override this routine to provide different behavior. |
| 876 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 877 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 878 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 879 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 880 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 881 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 882 | /// \brief Build a new declaration statement. |
| 883 | /// |
| 884 | /// By default, performs semantic analysis to build the new statement. |
| 885 | /// Subclasses may override this routine to provide different behavior. |
| 886 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 887 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 888 | SourceLocation EndLoc) { |
| 889 | return getSema().Owned( |
| 890 | new (getSema().Context) DeclStmt( |
| 891 | DeclGroupRef::Create(getSema().Context, |
| 892 | Decls, NumDecls), |
| 893 | StartLoc, EndLoc)); |
| 894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 896 | /// \brief Build a new inline asm statement. |
| 897 | /// |
| 898 | /// By default, performs semantic analysis to build the new statement. |
| 899 | /// Subclasses may override this routine to provide different behavior. |
| 900 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 901 | bool IsSimple, |
| 902 | bool IsVolatile, |
| 903 | unsigned NumOutputs, |
| 904 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 905 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 906 | MultiExprArg Constraints, |
| 907 | MultiExprArg Exprs, |
| 908 | ExprArg AsmString, |
| 909 | MultiExprArg Clobbers, |
| 910 | SourceLocation RParenLoc, |
| 911 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 912 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 913 | NumInputs, Names, move(Constraints), |
| 914 | move(Exprs), move(AsmString), move(Clobbers), |
| 915 | RParenLoc, MSAsm); |
| 916 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 917 | |
| 918 | /// \brief Build a new Objective-C @try statement. |
| 919 | /// |
| 920 | /// By default, performs semantic analysis to build the new statement. |
| 921 | /// Subclasses may override this routine to provide different behavior. |
| 922 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 923 | StmtArg TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 924 | MultiStmtArg CatchStmts, |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 925 | StmtArg Finally) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 926 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 927 | move(Finally)); |
| 928 | } |
| 929 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 930 | /// \brief Rebuild an Objective-C exception declaration. |
| 931 | /// |
| 932 | /// By default, performs semantic analysis to build the new declaration. |
| 933 | /// Subclasses may override this routine to provide different behavior. |
| 934 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 935 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 936 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 937 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 938 | ExceptionDecl->getLocation()); |
| 939 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 940 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 941 | /// \brief Build a new Objective-C @catch statement. |
| 942 | /// |
| 943 | /// By default, performs semantic analysis to build the new statement. |
| 944 | /// Subclasses may override this routine to provide different behavior. |
| 945 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 946 | SourceLocation RParenLoc, |
| 947 | VarDecl *Var, |
| 948 | StmtArg Body) { |
| 949 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 950 | Sema::DeclPtrTy::make(Var), |
| 951 | move(Body)); |
| 952 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 953 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 954 | /// \brief Build a new Objective-C @finally statement. |
| 955 | /// |
| 956 | /// By default, performs semantic analysis to build the new statement. |
| 957 | /// Subclasses may override this routine to provide different behavior. |
| 958 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 959 | StmtArg Body) { |
| 960 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 961 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 962 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 963 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 964 | /// |
| 965 | /// By default, performs semantic analysis to build the new statement. |
| 966 | /// Subclasses may override this routine to provide different behavior. |
| 967 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 968 | ExprArg Operand) { |
| 969 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 970 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 971 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 972 | /// \brief Build a new Objective-C @synchronized statement. |
| 973 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 974 | /// By default, performs semantic analysis to build the new statement. |
| 975 | /// Subclasses may override this routine to provide different behavior. |
| 976 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 977 | ExprArg Object, |
| 978 | StmtArg Body) { |
| 979 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 980 | move(Body)); |
| 981 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 982 | |
| 983 | /// \brief Build a new Objective-C fast enumeration statement. |
| 984 | /// |
| 985 | /// By default, performs semantic analysis to build the new statement. |
| 986 | /// Subclasses may override this routine to provide different behavior. |
| 987 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 988 | SourceLocation LParenLoc, |
| 989 | StmtArg Element, |
| 990 | ExprArg Collection, |
| 991 | SourceLocation RParenLoc, |
| 992 | StmtArg Body) { |
| 993 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 994 | move(Element), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 995 | move(Collection), |
| 996 | RParenLoc, |
| 997 | move(Body)); |
| 998 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 999 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1000 | /// \brief Build a new C++ exception declaration. |
| 1001 | /// |
| 1002 | /// By default, performs semantic analysis to build the new decaration. |
| 1003 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1005 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1006 | IdentifierInfo *Name, |
| 1007 | SourceLocation Loc, |
| 1008 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1010 | TypeRange); |
| 1011 | } |
| 1012 | |
| 1013 | /// \brief Build a new C++ catch statement. |
| 1014 | /// |
| 1015 | /// By default, performs semantic analysis to build the new statement. |
| 1016 | /// Subclasses may override this routine to provide different behavior. |
| 1017 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 1018 | VarDecl *ExceptionDecl, |
| 1019 | StmtArg Handler) { |
| 1020 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1021 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1022 | Handler.takeAs<Stmt>())); |
| 1023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1025 | /// \brief Build a new C++ try statement. |
| 1026 | /// |
| 1027 | /// By default, performs semantic analysis to build the new statement. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
| 1029 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1030 | StmtArg TryBlock, |
| 1031 | MultiStmtArg Handlers) { |
| 1032 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1033 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | /// \brief Build a new expression that references a declaration. |
| 1036 | /// |
| 1037 | /// By default, performs semantic analysis to build the new expression. |
| 1038 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1039 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1040 | LookupResult &R, |
| 1041 | bool RequiresADL) { |
| 1042 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | /// \brief Build a new expression that references a declaration. |
| 1047 | /// |
| 1048 | /// By default, performs semantic analysis to build the new expression. |
| 1049 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1050 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1051 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1052 | ValueDecl *VD, SourceLocation Loc, |
| 1053 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1054 | CXXScopeSpec SS; |
| 1055 | SS.setScopeRep(Qualifier); |
| 1056 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1057 | |
| 1058 | // FIXME: loses template args. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1059 | |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1060 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1063 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1065 | /// By default, performs semantic analysis to build the new expression. |
| 1066 | /// Subclasses may override this routine to provide different behavior. |
| 1067 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1068 | SourceLocation RParen) { |
| 1069 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1070 | } |
| 1071 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1072 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1073 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1074 | /// By default, performs semantic analysis to build the new expression. |
| 1075 | /// Subclasses may override this routine to provide different behavior. |
| 1076 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1077 | SourceLocation OperatorLoc, |
| 1078 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1079 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1080 | SourceRange QualifierRange, |
| 1081 | TypeSourceInfo *ScopeType, |
| 1082 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1083 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1084 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1086 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1088 | /// By default, performs semantic analysis to build the new expression. |
| 1089 | /// Subclasses may override this routine to provide different behavior. |
| 1090 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1091 | UnaryOperator::Opcode Opc, |
| 1092 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1093 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1096 | /// \brief Build a new builtin offsetof expression. |
| 1097 | /// |
| 1098 | /// By default, performs semantic analysis to build the new expression. |
| 1099 | /// Subclasses may override this routine to provide different behavior. |
| 1100 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1101 | TypeSourceInfo *Type, |
| 1102 | Action::OffsetOfComponent *Components, |
| 1103 | unsigned NumComponents, |
| 1104 | SourceLocation RParenLoc) { |
| 1105 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1106 | NumComponents, RParenLoc); |
| 1107 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1110 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1111 | /// By default, performs semantic analysis to build the new expression. |
| 1112 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1113 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1114 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1116 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | /// By default, performs semantic analysis to build the new expression. |
| 1123 | /// Subclasses may override this routine to provide different behavior. |
| 1124 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1125 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1128 | OpLoc, isSizeOf, R); |
| 1129 | if (Result.isInvalid()) |
| 1130 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1132 | SubExpr.release(); |
| 1133 | return move(Result); |
| 1134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1136 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | /// By default, performs semantic analysis to build the new expression. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | SourceLocation LBracketLoc, |
| 1142 | ExprArg RHS, |
| 1143 | SourceLocation RBracketLoc) { |
| 1144 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1146 | RBracketLoc); |
| 1147 | } |
| 1148 | |
| 1149 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1151 | /// By default, performs semantic analysis to build the new expression. |
| 1152 | /// Subclasses may override this routine to provide different behavior. |
| 1153 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1154 | MultiExprArg Args, |
| 1155 | SourceLocation *CommaLocs, |
| 1156 | SourceLocation RParenLoc) { |
| 1157 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1158 | move(Args), CommaLocs, RParenLoc); |
| 1159 | } |
| 1160 | |
| 1161 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1163 | /// By default, performs semantic analysis to build the new expression. |
| 1164 | /// Subclasses may override this routine to provide different behavior. |
| 1165 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1167 | NestedNameSpecifier *Qualifier, |
| 1168 | SourceRange QualifierRange, |
| 1169 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1170 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1171 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1172 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1173 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1174 | if (!Member->getDeclName()) { |
| 1175 | // We have a reference to an unnamed field. |
| 1176 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1178 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1179 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1180 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1181 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1182 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1183 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1184 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1185 | Member, MemberLoc, |
| 1186 | cast<FieldDecl>(Member)->getType()); |
| 1187 | return getSema().Owned(ME); |
| 1188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1190 | CXXScopeSpec SS; |
| 1191 | if (Qualifier) { |
| 1192 | SS.setRange(QualifierRange); |
| 1193 | SS.setScopeRep(Qualifier); |
| 1194 | } |
| 1195 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1196 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1197 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1198 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1199 | // cases; we should avoid this when possible. |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1200 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1201 | Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1202 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1203 | R.resolveKind(); |
| 1204 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1205 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1206 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1207 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1208 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1209 | } |
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 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | /// By default, performs semantic analysis to build the new expression. |
| 1214 | /// Subclasses may override this routine to provide different behavior. |
| 1215 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1216 | BinaryOperator::Opcode Opc, |
| 1217 | ExprArg LHS, ExprArg RHS) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1218 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1219 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | /// By default, performs semantic analysis to build the new expression. |
| 1225 | /// Subclasses may override this routine to provide different behavior. |
| 1226 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1227 | SourceLocation QuestionLoc, |
| 1228 | ExprArg LHS, |
| 1229 | SourceLocation ColonLoc, |
| 1230 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | move(LHS), move(RHS)); |
| 1233 | } |
| 1234 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1235 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | /// By default, performs semantic analysis to build the new expression. |
| 1238 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1239 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1240 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1241 | SourceLocation RParenLoc, |
| 1242 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1243 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1244 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1247 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1248 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1249 | /// By default, performs semantic analysis to build the new expression. |
| 1250 | /// Subclasses may override this routine to provide different behavior. |
| 1251 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1252 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1253 | SourceLocation RParenLoc, |
| 1254 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1255 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1256 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1257 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1259 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | /// By default, performs semantic analysis to build the new expression. |
| 1262 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1264 | SourceLocation OpLoc, |
| 1265 | SourceLocation AccessorLoc, |
| 1266 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1267 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1268 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1269 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1270 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1271 | OpLoc, /*IsArrow*/ false, |
| 1272 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1273 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1274 | AccessorLoc, |
| 1275 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1278 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | /// By default, performs semantic analysis to build the new expression. |
| 1281 | /// Subclasses may override this routine to provide different behavior. |
| 1282 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1283 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1284 | SourceLocation RBraceLoc, |
| 1285 | QualType ResultTy) { |
| 1286 | OwningExprResult Result |
| 1287 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1288 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1289 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1290 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1291 | // Patch in the result type we were given, which may have been computed |
| 1292 | // when the initial InitListExpr was built. |
| 1293 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1294 | ILE->setType(ResultTy); |
| 1295 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1298 | /// \brief Build a new designated initializer expression. |
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 RebuildDesignatedInitExpr(Designation &Desig, |
| 1303 | MultiExprArg ArrayExprs, |
| 1304 | SourceLocation EqualOrColonLoc, |
| 1305 | bool GNUSyntax, |
| 1306 | ExprArg Init) { |
| 1307 | OwningExprResult Result |
| 1308 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1309 | move(Init)); |
| 1310 | if (Result.isInvalid()) |
| 1311 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | ArrayExprs.release(); |
| 1314 | return move(Result); |
| 1315 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1317 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | /// By default, builds the implicit value initialization without performing |
| 1320 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1321 | /// different behavior. |
| 1322 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1323 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1328 | /// By default, performs semantic analysis to build the new expression. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1331 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1332 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1333 | RParenLoc); |
| 1334 | } |
| 1335 | |
| 1336 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | /// By default, performs semantic analysis to build the new expression. |
| 1339 | /// Subclasses may override this routine to provide different behavior. |
| 1340 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1341 | MultiExprArg SubExprs, |
| 1342 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1343 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1344 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1345 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | /// |
| 1349 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | /// rather than attempting to map the label statement itself. |
| 1351 | /// Subclasses may override this routine to provide different behavior. |
| 1352 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1353 | SourceLocation LabelLoc, |
| 1354 | LabelStmt *Label) { |
| 1355 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1356 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1360 | /// By default, performs semantic analysis to build the new expression. |
| 1361 | /// Subclasses may override this routine to provide different behavior. |
| 1362 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1363 | StmtArg SubStmt, |
| 1364 | SourceLocation RParenLoc) { |
| 1365 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1368 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1369 | /// |
| 1370 | /// By default, performs semantic analysis to build the new expression. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
| 1372 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1373 | QualType T1, QualType T2, |
| 1374 | SourceLocation RParenLoc) { |
| 1375 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1376 | T1.getAsOpaquePtr(), |
| 1377 | T2.getAsOpaquePtr(), |
| 1378 | RParenLoc); |
| 1379 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1380 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1381 | /// \brief Build a new __builtin_choose_expr expression. |
| 1382 | /// |
| 1383 | /// By default, performs semantic analysis to build the new expression. |
| 1384 | /// Subclasses may override this routine to provide different behavior. |
| 1385 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1386 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1387 | SourceLocation RParenLoc) { |
| 1388 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1389 | move(Cond), move(LHS), move(RHS), |
| 1390 | RParenLoc); |
| 1391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1393 | /// \brief Build a new overloaded operator call expression. |
| 1394 | /// |
| 1395 | /// By default, performs semantic analysis to build the new expression. |
| 1396 | /// The semantic analysis provides the behavior of template instantiation, |
| 1397 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1400 | /// provide different behavior. |
| 1401 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1402 | SourceLocation OpLoc, |
| 1403 | ExprArg Callee, |
| 1404 | ExprArg First, |
| 1405 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1406 | |
| 1407 | /// \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] | 1408 | /// reinterpret_cast. |
| 1409 | /// |
| 1410 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | /// Subclasses may override this routine to provide different behavior. |
| 1413 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1414 | Stmt::StmtClass Class, |
| 1415 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1416 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | SourceLocation RAngleLoc, |
| 1418 | SourceLocation LParenLoc, |
| 1419 | ExprArg SubExpr, |
| 1420 | SourceLocation RParenLoc) { |
| 1421 | switch (Class) { |
| 1422 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1423 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | move(SubExpr), RParenLoc); |
| 1426 | |
| 1427 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1428 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1431 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1432 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1433 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | RAngleLoc, LParenLoc, |
| 1435 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1439 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1440 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1441 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1442 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | default: |
| 1444 | assert(false && "Invalid C++ named cast"); |
| 1445 | break; |
| 1446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | return getSema().ExprError(); |
| 1449 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | /// \brief Build a new C++ static_cast expression. |
| 1452 | /// |
| 1453 | /// By default, performs semantic analysis to build the new expression. |
| 1454 | /// Subclasses may override this routine to provide different behavior. |
| 1455 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1456 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1457 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1458 | SourceLocation RAngleLoc, |
| 1459 | SourceLocation LParenLoc, |
| 1460 | ExprArg SubExpr, |
| 1461 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1462 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1463 | TInfo, move(SubExpr), |
| 1464 | SourceRange(LAngleLoc, RAngleLoc), |
| 1465 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /// \brief Build a new C++ dynamic_cast expression. |
| 1469 | /// |
| 1470 | /// By default, performs semantic analysis to build the new expression. |
| 1471 | /// Subclasses may override this routine to provide different behavior. |
| 1472 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1473 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1474 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | SourceLocation RAngleLoc, |
| 1476 | SourceLocation LParenLoc, |
| 1477 | ExprArg SubExpr, |
| 1478 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1479 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1480 | TInfo, move(SubExpr), |
| 1481 | SourceRange(LAngleLoc, RAngleLoc), |
| 1482 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1486 | /// |
| 1487 | /// By default, performs semantic analysis to build the new expression. |
| 1488 | /// Subclasses may override this routine to provide different behavior. |
| 1489 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1490 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1491 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | SourceLocation RAngleLoc, |
| 1493 | SourceLocation LParenLoc, |
| 1494 | ExprArg SubExpr, |
| 1495 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1496 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1497 | TInfo, move(SubExpr), |
| 1498 | SourceRange(LAngleLoc, RAngleLoc), |
| 1499 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /// \brief Build a new C++ const_cast expression. |
| 1503 | /// |
| 1504 | /// By default, performs semantic analysis to build the new expression. |
| 1505 | /// Subclasses may override this routine to provide different behavior. |
| 1506 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1507 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1508 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1509 | SourceLocation RAngleLoc, |
| 1510 | SourceLocation LParenLoc, |
| 1511 | ExprArg SubExpr, |
| 1512 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1513 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1514 | TInfo, move(SubExpr), |
| 1515 | SourceRange(LAngleLoc, RAngleLoc), |
| 1516 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1518 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1519 | /// \brief Build a new C++ functional-style cast expression. |
| 1520 | /// |
| 1521 | /// By default, performs semantic analysis to build the new expression. |
| 1522 | /// Subclasses may override this routine to provide different behavior. |
| 1523 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1524 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | SourceLocation LParenLoc, |
| 1526 | ExprArg SubExpr, |
| 1527 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1528 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1529 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1530 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1531 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1532 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | RParenLoc); |
| 1535 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1536 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | /// \brief Build a new C++ typeid(type) expression. |
| 1538 | /// |
| 1539 | /// By default, performs semantic analysis to build the new expression. |
| 1540 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1541 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1542 | SourceLocation TypeidLoc, |
| 1543 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1545 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1546 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | /// \brief Build a new C++ typeid(expr) expression. |
| 1550 | /// |
| 1551 | /// By default, performs semantic analysis to build the new expression. |
| 1552 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1553 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1554 | SourceLocation TypeidLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | ExprArg Operand, |
| 1556 | SourceLocation RParenLoc) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1557 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1558 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1561 | /// \brief Build a new C++ "this" expression. |
| 1562 | /// |
| 1563 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1564 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1566 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1567 | QualType ThisType, |
| 1568 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1570 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1571 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | /// \brief Build a new C++ throw expression. |
| 1575 | /// |
| 1576 | /// By default, performs semantic analysis to build the new expression. |
| 1577 | /// Subclasses may override this routine to provide different behavior. |
| 1578 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1579 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1580 | } |
| 1581 | |
| 1582 | /// \brief Build a new C++ default-argument expression. |
| 1583 | /// |
| 1584 | /// By default, builds a new default-argument expression, which does not |
| 1585 | /// require any semantic analysis. Subclasses may override this routine to |
| 1586 | /// provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1587 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1588 | ParmVarDecl *Param) { |
| 1589 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1590 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | /// \brief Build a new C++ zero-initialization expression. |
| 1594 | /// |
| 1595 | /// By default, performs semantic analysis to build the new expression. |
| 1596 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1597 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1598 | SourceLocation LParenLoc, |
| 1599 | QualType T, |
| 1600 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1602 | T.getAsOpaquePtr(), LParenLoc, |
| 1603 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | 0, RParenLoc); |
| 1605 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1607 | /// \brief Build a new C++ "new" expression. |
| 1608 | /// |
| 1609 | /// By default, performs semantic analysis to build the new expression. |
| 1610 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1612 | bool UseGlobal, |
| 1613 | SourceLocation PlacementLParen, |
| 1614 | MultiExprArg PlacementArgs, |
| 1615 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1616 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | QualType AllocType, |
| 1618 | SourceLocation TypeLoc, |
| 1619 | SourceRange TypeRange, |
| 1620 | ExprArg ArraySize, |
| 1621 | SourceLocation ConstructorLParen, |
| 1622 | MultiExprArg ConstructorArgs, |
| 1623 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | PlacementLParen, |
| 1626 | move(PlacementArgs), |
| 1627 | PlacementRParen, |
| 1628 | ParenTypeId, |
| 1629 | AllocType, |
| 1630 | TypeLoc, |
| 1631 | TypeRange, |
| 1632 | move(ArraySize), |
| 1633 | ConstructorLParen, |
| 1634 | move(ConstructorArgs), |
| 1635 | ConstructorRParen); |
| 1636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1638 | /// \brief Build a new C++ "delete" expression. |
| 1639 | /// |
| 1640 | /// By default, performs semantic analysis to build the new expression. |
| 1641 | /// Subclasses may override this routine to provide different behavior. |
| 1642 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1643 | bool IsGlobalDelete, |
| 1644 | bool IsArrayForm, |
| 1645 | ExprArg Operand) { |
| 1646 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1647 | move(Operand)); |
| 1648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | /// \brief Build a new unary type trait expression. |
| 1651 | /// |
| 1652 | /// By default, performs semantic analysis to build the new expression. |
| 1653 | /// Subclasses may override this routine to provide different behavior. |
| 1654 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1655 | SourceLocation StartLoc, |
| 1656 | SourceLocation LParenLoc, |
| 1657 | QualType T, |
| 1658 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1660 | T.getAsOpaquePtr(), RParenLoc); |
| 1661 | } |
| 1662 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1663 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1664 | /// expression. |
| 1665 | /// |
| 1666 | /// By default, performs semantic analysis to build the new expression. |
| 1667 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1668 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1669 | SourceRange QualifierRange, |
| 1670 | DeclarationName Name, |
| 1671 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1672 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1673 | CXXScopeSpec SS; |
| 1674 | SS.setRange(QualifierRange); |
| 1675 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1676 | |
| 1677 | if (TemplateArgs) |
| 1678 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1679 | *TemplateArgs); |
| 1680 | |
| 1681 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | /// \brief Build a new template-id expression. |
| 1685 | /// |
| 1686 | /// By default, performs semantic analysis to build the new expression. |
| 1687 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1688 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1689 | LookupResult &R, |
| 1690 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1691 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1692 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | /// \brief Build a new object-construction expression. |
| 1696 | /// |
| 1697 | /// By default, performs semantic analysis to build the new expression. |
| 1698 | /// Subclasses may override this routine to provide different behavior. |
| 1699 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1700 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1701 | CXXConstructorDecl *Constructor, |
| 1702 | bool IsElidable, |
| 1703 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1704 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1705 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1706 | ConvertedArgs)) |
| 1707 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1709 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1710 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | /// \brief Build a new object-construction expression. |
| 1714 | /// |
| 1715 | /// By default, performs semantic analysis to build the new expression. |
| 1716 | /// Subclasses may override this routine to provide different behavior. |
| 1717 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1718 | QualType T, |
| 1719 | SourceLocation LParenLoc, |
| 1720 | MultiExprArg Args, |
| 1721 | SourceLocation *Commas, |
| 1722 | SourceLocation RParenLoc) { |
| 1723 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1724 | T.getAsOpaquePtr(), |
| 1725 | LParenLoc, |
| 1726 | move(Args), |
| 1727 | Commas, |
| 1728 | RParenLoc); |
| 1729 | } |
| 1730 | |
| 1731 | /// \brief Build a new object-construction expression. |
| 1732 | /// |
| 1733 | /// By default, performs semantic analysis to build the new expression. |
| 1734 | /// Subclasses may override this routine to provide different behavior. |
| 1735 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1736 | QualType T, |
| 1737 | SourceLocation LParenLoc, |
| 1738 | MultiExprArg Args, |
| 1739 | SourceLocation *Commas, |
| 1740 | SourceLocation RParenLoc) { |
| 1741 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1742 | /*FIXME*/LParenLoc), |
| 1743 | T.getAsOpaquePtr(), |
| 1744 | LParenLoc, |
| 1745 | move(Args), |
| 1746 | Commas, |
| 1747 | RParenLoc); |
| 1748 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1750 | /// \brief Build a new member reference expression. |
| 1751 | /// |
| 1752 | /// By default, performs semantic analysis to build the new expression. |
| 1753 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1754 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1755 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1756 | bool IsArrow, |
| 1757 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1758 | NestedNameSpecifier *Qualifier, |
| 1759 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1760 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1761 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1762 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1763 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1764 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1765 | SS.setRange(QualifierRange); |
| 1766 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1768 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1769 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1770 | SS, FirstQualifierInScope, |
| 1771 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1774 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1775 | /// |
| 1776 | /// By default, performs semantic analysis to build the new expression. |
| 1777 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1778 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1779 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1780 | SourceLocation OperatorLoc, |
| 1781 | bool IsArrow, |
| 1782 | NestedNameSpecifier *Qualifier, |
| 1783 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1784 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1785 | LookupResult &R, |
| 1786 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1787 | CXXScopeSpec SS; |
| 1788 | SS.setRange(QualifierRange); |
| 1789 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1791 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1792 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1793 | SS, FirstQualifierInScope, |
| 1794 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1797 | /// \brief Build a new Objective-C @encode expression. |
| 1798 | /// |
| 1799 | /// By default, performs semantic analysis to build the new expression. |
| 1800 | /// Subclasses may override this routine to provide different behavior. |
| 1801 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1802 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1803 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1804 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1805 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1806 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1807 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1808 | /// \brief Build a new Objective-C class message. |
| 1809 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1810 | Selector Sel, |
| 1811 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1812 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1813 | MultiExprArg Args, |
| 1814 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1815 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1816 | ReceiverTypeInfo->getType(), |
| 1817 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1818 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1819 | move(Args)); |
| 1820 | } |
| 1821 | |
| 1822 | /// \brief Build a new Objective-C instance message. |
| 1823 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1824 | Selector Sel, |
| 1825 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1826 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1827 | MultiExprArg Args, |
| 1828 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1829 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1830 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1831 | ReceiverType, |
| 1832 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1833 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1834 | move(Args)); |
| 1835 | } |
| 1836 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1837 | /// \brief Build a new Objective-C ivar reference expression. |
| 1838 | /// |
| 1839 | /// By default, performs semantic analysis to build the new expression. |
| 1840 | /// Subclasses may override this routine to provide different behavior. |
| 1841 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1842 | SourceLocation IvarLoc, |
| 1843 | bool IsArrow, bool IsFreeIvar) { |
| 1844 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1845 | CXXScopeSpec SS; |
| 1846 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1847 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1848 | Sema::LookupMemberName); |
| 1849 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1850 | /*FIME:*/IvarLoc, |
| 1851 | SS, DeclPtrTy()); |
| 1852 | if (Result.isInvalid()) |
| 1853 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1855 | if (Result.get()) |
| 1856 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1857 | |
| 1858 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1859 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1860 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1861 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1862 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1863 | /*TemplateArgs=*/0); |
| 1864 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1865 | |
| 1866 | /// \brief Build a new Objective-C property reference expression. |
| 1867 | /// |
| 1868 | /// By default, performs semantic analysis to build the new expression. |
| 1869 | /// Subclasses may override this routine to provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1870 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1871 | ObjCPropertyDecl *Property, |
| 1872 | SourceLocation PropertyLoc) { |
| 1873 | CXXScopeSpec SS; |
| 1874 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1875 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1876 | Sema::LookupMemberName); |
| 1877 | bool IsArrow = false; |
| 1878 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1879 | /*FIME:*/PropertyLoc, |
| 1880 | SS, DeclPtrTy()); |
| 1881 | if (Result.isInvalid()) |
| 1882 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1883 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1884 | if (Result.get()) |
| 1885 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1886 | |
| 1887 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1888 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1889 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1890 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1891 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1892 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1893 | /*TemplateArgs=*/0); |
| 1894 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1895 | |
| 1896 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1897 | /// expression. |
| 1898 | /// |
| 1899 | /// By default, performs semantic analysis to build the new expression. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1900 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1901 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1902 | ObjCMethodDecl *Getter, |
| 1903 | QualType T, |
| 1904 | ObjCMethodDecl *Setter, |
| 1905 | SourceLocation NameLoc, |
| 1906 | ExprArg Base) { |
| 1907 | // Since these expressions can only be value-dependent, we do not need to |
| 1908 | // perform semantic analysis again. |
| 1909 | return getSema().Owned( |
| 1910 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1911 | Setter, |
| 1912 | NameLoc, |
| 1913 | Base.takeAs<Expr>())); |
| 1914 | } |
| 1915 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1916 | /// \brief Build a new Objective-C "isa" expression. |
| 1917 | /// |
| 1918 | /// By default, performs semantic analysis to build the new expression. |
| 1919 | /// Subclasses may override this routine to provide different behavior. |
| 1920 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1921 | bool IsArrow) { |
| 1922 | CXXScopeSpec SS; |
| 1923 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1924 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1925 | Sema::LookupMemberName); |
| 1926 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1927 | /*FIME:*/IsaLoc, |
| 1928 | SS, DeclPtrTy()); |
| 1929 | if (Result.isInvalid()) |
| 1930 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1931 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1932 | if (Result.get()) |
| 1933 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1934 | |
| 1935 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1936 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1937 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1938 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1939 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1940 | /*TemplateArgs=*/0); |
| 1941 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1942 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1943 | /// \brief Build a new shuffle vector expression. |
| 1944 | /// |
| 1945 | /// By default, performs semantic analysis to build the new expression. |
| 1946 | /// Subclasses may override this routine to provide different behavior. |
| 1947 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1948 | MultiExprArg SubExprs, |
| 1949 | SourceLocation RParenLoc) { |
| 1950 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1951 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1952 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1953 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1954 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1955 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1956 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1957 | // Build a reference to the __builtin_shufflevector builtin |
| 1958 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1959 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1960 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1961 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1962 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1963 | |
| 1964 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1965 | unsigned NumSubExprs = SubExprs.size(); |
| 1966 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1967 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1968 | Subs, NumSubExprs, |
| 1969 | Builtin->getResultType(), |
| 1970 | RParenLoc); |
| 1971 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1973 | // Type-check the __builtin_shufflevector expression. |
| 1974 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1975 | if (Result.isInvalid()) |
| 1976 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1978 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1980 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1981 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1982 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1983 | template<typename Derived> |
| 1984 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1985 | if (!S) |
| 1986 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1988 | switch (S->getStmtClass()) { |
| 1989 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1990 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1991 | // Transform individual statement nodes |
| 1992 | #define STMT(Node, Parent) \ |
| 1993 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1994 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1995 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1997 | // Transform expressions by calling TransformExpr. |
| 1998 | #define STMT(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1999 | #define ABSTRACT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2000 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2001 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2002 | { |
| 2003 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 2004 | if (E.isInvalid()) |
| 2005 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2006 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 2007 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2011 | return SemaRef.Owned(S->Retain()); |
| 2012 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | |
| 2014 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2015 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2016 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2017 | if (!E) |
| 2018 | return SemaRef.Owned(E); |
| 2019 | |
| 2020 | switch (E->getStmtClass()) { |
| 2021 | case Stmt::NoStmtClass: break; |
| 2022 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2023 | #define ABSTRACT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2024 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2025 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2026 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2029 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2033 | NestedNameSpecifier * |
| 2034 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2035 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2036 | QualType ObjectType, |
| 2037 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2038 | if (!NNS) |
| 2039 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2041 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2042 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2043 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2045 | ObjectType, |
| 2046 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2047 | if (!Prefix) |
| 2048 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2049 | |
| 2050 | // 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] | 2051 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2052 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2053 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2055 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2056 | switch (NNS->getKind()) { |
| 2057 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2059 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2060 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2061 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2062 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2063 | |
| 2064 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2065 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2066 | ObjectType, |
| 2067 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2068 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2069 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2070 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2071 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2072 | getDerived().TransformDecl(Range.getBegin(), |
| 2073 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2074 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2075 | Prefix == NNS->getPrefix() && |
| 2076 | NS == NNS->getAsNamespace()) |
| 2077 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2078 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2079 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2082 | case NestedNameSpecifier::Global: |
| 2083 | // There is no meaningful transformation that one could perform on the |
| 2084 | // global scope. |
| 2085 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2086 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2087 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2088 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2089 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2090 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2091 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2092 | if (T.isNull()) |
| 2093 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2095 | if (!getDerived().AlwaysRebuild() && |
| 2096 | Prefix == NNS->getPrefix() && |
| 2097 | T == QualType(NNS->getAsType(), 0)) |
| 2098 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2099 | |
| 2100 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2101 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2102 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2103 | } |
| 2104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2105 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2106 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2107 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2111 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2112 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2113 | SourceLocation Loc, |
| 2114 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2115 | if (!Name) |
| 2116 | return Name; |
| 2117 | |
| 2118 | switch (Name.getNameKind()) { |
| 2119 | case DeclarationName::Identifier: |
| 2120 | case DeclarationName::ObjCZeroArgSelector: |
| 2121 | case DeclarationName::ObjCOneArgSelector: |
| 2122 | case DeclarationName::ObjCMultiArgSelector: |
| 2123 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2124 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2125 | case DeclarationName::CXXUsingDirective: |
| 2126 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2127 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2128 | case DeclarationName::CXXConstructorName: |
| 2129 | case DeclarationName::CXXDestructorName: |
| 2130 | case DeclarationName::CXXConversionFunctionName: { |
| 2131 | TemporaryBase Rebase(*this, Loc, Name); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2132 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2133 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2134 | if (T.isNull()) |
| 2135 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2136 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2137 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2138 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2139 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2143 | return DeclarationName(); |
| 2144 | } |
| 2145 | |
| 2146 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2148 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2149 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2150 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2151 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2152 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2153 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2154 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2155 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2156 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2157 | if (!NNS) |
| 2158 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2159 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2160 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2161 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2162 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2163 | if (!TransTemplate) |
| 2164 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2165 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2166 | if (!getDerived().AlwaysRebuild() && |
| 2167 | NNS == QTN->getQualifier() && |
| 2168 | TransTemplate == Template) |
| 2169 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2171 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2172 | 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 make it into the AST. |
| 2176 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2178 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2179 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2180 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2181 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2182 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2183 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2184 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2185 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2186 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2187 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2188 | NNS == DTN->getQualifier() && |
| 2189 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2190 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2192 | if (DTN->isIdentifier()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2193 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2194 | ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2195 | |
| 2196 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2197 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2200 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2201 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2202 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2203 | if (!TransTemplate) |
| 2204 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2205 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2206 | if (!getDerived().AlwaysRebuild() && |
| 2207 | TransTemplate == Template) |
| 2208 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2209 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2210 | return TemplateName(TransTemplate); |
| 2211 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2213 | // These should be getting filtered out before they reach the AST. |
| 2214 | assert(false && "overloaded function decl survived to here"); |
| 2215 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2219 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2220 | const TemplateArgument &Arg, |
| 2221 | TemplateArgumentLoc &Output) { |
| 2222 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2223 | switch (Arg.getKind()) { |
| 2224 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2225 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2226 | break; |
| 2227 | |
| 2228 | case TemplateArgument::Type: |
| 2229 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2230 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2231 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2232 | break; |
| 2233 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2234 | case TemplateArgument::Template: |
| 2235 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2236 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2237 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2238 | case TemplateArgument::Expression: |
| 2239 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2240 | break; |
| 2241 | |
| 2242 | case TemplateArgument::Declaration: |
| 2243 | case TemplateArgument::Integral: |
| 2244 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2245 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2246 | break; |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | template<typename Derived> |
| 2251 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2252 | const TemplateArgumentLoc &Input, |
| 2253 | TemplateArgumentLoc &Output) { |
| 2254 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2255 | switch (Arg.getKind()) { |
| 2256 | case TemplateArgument::Null: |
| 2257 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2258 | Output = Input; |
| 2259 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2261 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2262 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2263 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2264 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2265 | |
| 2266 | DI = getDerived().TransformType(DI); |
| 2267 | if (!DI) return true; |
| 2268 | |
| 2269 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2270 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2271 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2272 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2273 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2274 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2275 | DeclarationName Name; |
| 2276 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2277 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2278 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2279 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2280 | if (!D) return true; |
| 2281 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2282 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2283 | if (SourceExpr) { |
| 2284 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2285 | Action::Unevaluated); |
| 2286 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2287 | if (E.isInvalid()) |
| 2288 | SourceExpr = NULL; |
| 2289 | else { |
| 2290 | SourceExpr = E.takeAs<Expr>(); |
| 2291 | SourceExpr->Retain(); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2296 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2297 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2299 | case TemplateArgument::Template: { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2300 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2301 | TemplateName Template |
| 2302 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2303 | if (Template.isNull()) |
| 2304 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2305 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2306 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2307 | Input.getTemplateQualifierRange(), |
| 2308 | Input.getTemplateNameLoc()); |
| 2309 | return false; |
| 2310 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2312 | case TemplateArgument::Expression: { |
| 2313 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2314 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2315 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2316 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2317 | Expr *InputExpr = Input.getSourceExpression(); |
| 2318 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2319 | |
| 2320 | Sema::OwningExprResult E |
| 2321 | = getDerived().TransformExpr(InputExpr); |
| 2322 | if (E.isInvalid()) return true; |
| 2323 | |
| 2324 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2325 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2326 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2327 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2328 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2329 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2330 | case TemplateArgument::Pack: { |
| 2331 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2332 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2333 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2334 | AEnd = Arg.pack_end(); |
| 2335 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2337 | // FIXME: preserve source information here when we start |
| 2338 | // caring about parameter packs. |
| 2339 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2340 | TemplateArgumentLoc InputArg; |
| 2341 | TemplateArgumentLoc OutputArg; |
| 2342 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2343 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2344 | return true; |
| 2345 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2346 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2347 | } |
| 2348 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2349 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2350 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2351 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2352 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2353 | } |
| 2354 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2355 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2356 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2357 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2360 | //===----------------------------------------------------------------------===// |
| 2361 | // Type transformation |
| 2362 | //===----------------------------------------------------------------------===// |
| 2363 | |
| 2364 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2365 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2366 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2367 | if (getDerived().AlreadyTransformed(T)) |
| 2368 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2369 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2370 | // Temporary workaround. All of these transformations should |
| 2371 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2372 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2373 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2374 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2375 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2376 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2377 | if (!NewDI) |
| 2378 | return QualType(); |
| 2379 | |
| 2380 | return NewDI->getType(); |
| 2381 | } |
| 2382 | |
| 2383 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2384 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2385 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2386 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2387 | return DI; |
| 2388 | |
| 2389 | TypeLocBuilder TLB; |
| 2390 | |
| 2391 | TypeLoc TL = DI->getTypeLoc(); |
| 2392 | TLB.reserve(TL.getFullDataSize()); |
| 2393 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2394 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2395 | if (Result.isNull()) |
| 2396 | return 0; |
| 2397 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2398 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | template<typename Derived> |
| 2402 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2403 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2404 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2405 | switch (T.getTypeLocClass()) { |
| 2406 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2407 | #define TYPELOC(CLASS, PARENT) \ |
| 2408 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2409 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2410 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2411 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2412 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2413 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2414 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2415 | return QualType(); |
| 2416 | } |
| 2417 | |
| 2418 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2419 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2420 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2421 | /// types). This is the right thing for template instantiation, but |
| 2422 | /// probably not for other clients. |
| 2423 | template<typename Derived> |
| 2424 | QualType |
| 2425 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2426 | QualifiedTypeLoc T, |
| 2427 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2428 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2429 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2430 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2431 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2432 | if (Result.isNull()) |
| 2433 | return QualType(); |
| 2434 | |
| 2435 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2436 | // FIXME: this is the right thing for template instantiation, but |
| 2437 | // probably not for other clients. |
| 2438 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2439 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2441 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2442 | |
| 2443 | TLB.push<QualifiedTypeLoc>(Result); |
| 2444 | |
| 2445 | // No location information to preserve. |
| 2446 | |
| 2447 | return Result; |
| 2448 | } |
| 2449 | |
| 2450 | template <class TyLoc> static inline |
| 2451 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2452 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2453 | NewT.setNameLoc(T.getNameLoc()); |
| 2454 | return T.getType(); |
| 2455 | } |
| 2456 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2457 | template<typename Derived> |
| 2458 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2459 | BuiltinTypeLoc T, |
| 2460 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2461 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2462 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2463 | if (T.needsExtraLocalData()) |
| 2464 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2465 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2466 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2467 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2468 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2469 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2470 | ComplexTypeLoc T, |
| 2471 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2472 | // FIXME: recurse? |
| 2473 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2475 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2476 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2477 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2478 | PointerTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2479 | QualType ObjectType) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2480 | QualType PointeeType |
| 2481 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2482 | if (PointeeType.isNull()) |
| 2483 | return QualType(); |
| 2484 | |
| 2485 | QualType Result = TL.getType(); |
| 2486 | if (PointeeType->isObjCInterfaceType()) { |
| 2487 | // A dependent pointer type 'T *' has is being transformed such |
| 2488 | // that an Objective-C class type is being replaced for 'T'. The |
| 2489 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2490 | // PointerType. |
| 2491 | const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>(); |
| 2492 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType, |
| 2493 | const_cast<ObjCProtocolDecl **>( |
| 2494 | IFace->qual_begin()), |
| 2495 | IFace->getNumProtocols()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2496 | |
| 2497 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2498 | NewT.setStarLoc(TL.getSigilLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2499 | NewT.setHasProtocolsAsWritten(false); |
| 2500 | NewT.setLAngleLoc(SourceLocation()); |
| 2501 | NewT.setRAngleLoc(SourceLocation()); |
| 2502 | NewT.setHasBaseTypeAsWritten(true); |
| 2503 | return Result; |
| 2504 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2505 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2506 | if (getDerived().AlwaysRebuild() || |
| 2507 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2508 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2509 | if (Result.isNull()) |
| 2510 | return QualType(); |
| 2511 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2512 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2513 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2514 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2515 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2517 | |
| 2518 | template<typename Derived> |
| 2519 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2520 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2521 | BlockPointerTypeLoc TL, |
| 2522 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2523 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2524 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2525 | if (PointeeType.isNull()) |
| 2526 | return QualType(); |
| 2527 | |
| 2528 | QualType Result = TL.getType(); |
| 2529 | if (getDerived().AlwaysRebuild() || |
| 2530 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2531 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2532 | TL.getSigilLoc()); |
| 2533 | if (Result.isNull()) |
| 2534 | return QualType(); |
| 2535 | } |
| 2536 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2537 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2538 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2539 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2542 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2543 | /// don't care whether the type itself is an l-value type or an r-value |
| 2544 | /// type; we only care if the type was *written* as an l-value type |
| 2545 | /// or an r-value type. |
| 2546 | template<typename Derived> |
| 2547 | QualType |
| 2548 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2549 | ReferenceTypeLoc TL, |
| 2550 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2551 | const ReferenceType *T = TL.getTypePtr(); |
| 2552 | |
| 2553 | // Note that this works with the pointee-as-written. |
| 2554 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2555 | if (PointeeType.isNull()) |
| 2556 | return QualType(); |
| 2557 | |
| 2558 | QualType Result = TL.getType(); |
| 2559 | if (getDerived().AlwaysRebuild() || |
| 2560 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2561 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2562 | T->isSpelledAsLValue(), |
| 2563 | TL.getSigilLoc()); |
| 2564 | if (Result.isNull()) |
| 2565 | return QualType(); |
| 2566 | } |
| 2567 | |
| 2568 | // r-value references can be rebuilt as l-value references. |
| 2569 | ReferenceTypeLoc NewTL; |
| 2570 | if (isa<LValueReferenceType>(Result)) |
| 2571 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2572 | else |
| 2573 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2574 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2575 | |
| 2576 | return Result; |
| 2577 | } |
| 2578 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2579 | template<typename Derived> |
| 2580 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2581 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2582 | LValueReferenceTypeLoc TL, |
| 2583 | QualType ObjectType) { |
| 2584 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | template<typename Derived> |
| 2588 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2589 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2590 | RValueReferenceTypeLoc TL, |
| 2591 | QualType ObjectType) { |
| 2592 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2594 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2595 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2596 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2597 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2598 | MemberPointerTypeLoc TL, |
| 2599 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2600 | MemberPointerType *T = TL.getTypePtr(); |
| 2601 | |
| 2602 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2603 | if (PointeeType.isNull()) |
| 2604 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2605 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2606 | // TODO: preserve source information for this. |
| 2607 | QualType ClassType |
| 2608 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2609 | if (ClassType.isNull()) |
| 2610 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2611 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2612 | QualType Result = TL.getType(); |
| 2613 | if (getDerived().AlwaysRebuild() || |
| 2614 | PointeeType != T->getPointeeType() || |
| 2615 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2616 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2617 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2618 | if (Result.isNull()) |
| 2619 | return QualType(); |
| 2620 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2621 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2622 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2623 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2624 | |
| 2625 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2628 | template<typename Derived> |
| 2629 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2630 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2631 | ConstantArrayTypeLoc TL, |
| 2632 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2633 | ConstantArrayType *T = TL.getTypePtr(); |
| 2634 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2635 | if (ElementType.isNull()) |
| 2636 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2637 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2638 | QualType Result = TL.getType(); |
| 2639 | if (getDerived().AlwaysRebuild() || |
| 2640 | ElementType != T->getElementType()) { |
| 2641 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2642 | T->getSizeModifier(), |
| 2643 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2644 | T->getIndexTypeCVRQualifiers(), |
| 2645 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2646 | if (Result.isNull()) |
| 2647 | return QualType(); |
| 2648 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2649 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2650 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2651 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2652 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2653 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2654 | Expr *Size = TL.getSizeExpr(); |
| 2655 | if (Size) { |
| 2656 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2657 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2658 | } |
| 2659 | NewTL.setSizeExpr(Size); |
| 2660 | |
| 2661 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2662 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2663 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2664 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2665 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2666 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2667 | IncompleteArrayTypeLoc TL, |
| 2668 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2669 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2670 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2671 | if (ElementType.isNull()) |
| 2672 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2673 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2674 | QualType Result = TL.getType(); |
| 2675 | if (getDerived().AlwaysRebuild() || |
| 2676 | ElementType != T->getElementType()) { |
| 2677 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2678 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2679 | T->getIndexTypeCVRQualifiers(), |
| 2680 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2681 | if (Result.isNull()) |
| 2682 | return QualType(); |
| 2683 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2684 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2685 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2686 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2687 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2688 | NewTL.setSizeExpr(0); |
| 2689 | |
| 2690 | return Result; |
| 2691 | } |
| 2692 | |
| 2693 | template<typename Derived> |
| 2694 | QualType |
| 2695 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2696 | VariableArrayTypeLoc TL, |
| 2697 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2698 | VariableArrayType *T = TL.getTypePtr(); |
| 2699 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2700 | if (ElementType.isNull()) |
| 2701 | return QualType(); |
| 2702 | |
| 2703 | // Array bounds are not potentially evaluated contexts |
| 2704 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2705 | |
| 2706 | Sema::OwningExprResult SizeResult |
| 2707 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2708 | if (SizeResult.isInvalid()) |
| 2709 | return QualType(); |
| 2710 | |
| 2711 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2712 | |
| 2713 | QualType Result = TL.getType(); |
| 2714 | if (getDerived().AlwaysRebuild() || |
| 2715 | ElementType != T->getElementType() || |
| 2716 | Size != T->getSizeExpr()) { |
| 2717 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2718 | T->getSizeModifier(), |
| 2719 | move(SizeResult), |
| 2720 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2721 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2722 | if (Result.isNull()) |
| 2723 | return QualType(); |
| 2724 | } |
| 2725 | else SizeResult.take(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2726 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2727 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2728 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2729 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2730 | NewTL.setSizeExpr(Size); |
| 2731 | |
| 2732 | return Result; |
| 2733 | } |
| 2734 | |
| 2735 | template<typename Derived> |
| 2736 | QualType |
| 2737 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2738 | DependentSizedArrayTypeLoc TL, |
| 2739 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2740 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2741 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2742 | if (ElementType.isNull()) |
| 2743 | return QualType(); |
| 2744 | |
| 2745 | // Array bounds are not potentially evaluated contexts |
| 2746 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2747 | |
| 2748 | Sema::OwningExprResult SizeResult |
| 2749 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2750 | if (SizeResult.isInvalid()) |
| 2751 | return QualType(); |
| 2752 | |
| 2753 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2754 | |
| 2755 | QualType Result = TL.getType(); |
| 2756 | if (getDerived().AlwaysRebuild() || |
| 2757 | ElementType != T->getElementType() || |
| 2758 | Size != T->getSizeExpr()) { |
| 2759 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2760 | T->getSizeModifier(), |
| 2761 | move(SizeResult), |
| 2762 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2763 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2764 | if (Result.isNull()) |
| 2765 | return QualType(); |
| 2766 | } |
| 2767 | else SizeResult.take(); |
| 2768 | |
| 2769 | // We might have any sort of array type now, but fortunately they |
| 2770 | // all have the same location layout. |
| 2771 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2772 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2773 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2774 | NewTL.setSizeExpr(Size); |
| 2775 | |
| 2776 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2778 | |
| 2779 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2780 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2781 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2782 | DependentSizedExtVectorTypeLoc TL, |
| 2783 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2784 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2785 | |
| 2786 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2787 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2788 | if (ElementType.isNull()) |
| 2789 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2790 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2791 | // Vector sizes are not potentially evaluated contexts |
| 2792 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2793 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2794 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2795 | if (Size.isInvalid()) |
| 2796 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2797 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2798 | QualType Result = TL.getType(); |
| 2799 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2800 | ElementType != T->getElementType() || |
| 2801 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2803 | move(Size), |
| 2804 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2805 | if (Result.isNull()) |
| 2806 | return QualType(); |
| 2807 | } |
| 2808 | else Size.take(); |
| 2809 | |
| 2810 | // Result might be dependent or not. |
| 2811 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2812 | DependentSizedExtVectorTypeLoc NewTL |
| 2813 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2814 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2815 | } else { |
| 2816 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2817 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2818 | } |
| 2819 | |
| 2820 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2821 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2822 | |
| 2823 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2824 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2825 | VectorTypeLoc TL, |
| 2826 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2827 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2828 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2829 | if (ElementType.isNull()) |
| 2830 | return QualType(); |
| 2831 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2832 | QualType Result = TL.getType(); |
| 2833 | if (getDerived().AlwaysRebuild() || |
| 2834 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2835 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2836 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | if (Result.isNull()) |
| 2838 | return QualType(); |
| 2839 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2840 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2841 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2842 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2843 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2844 | return Result; |
| 2845 | } |
| 2846 | |
| 2847 | template<typename Derived> |
| 2848 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2849 | ExtVectorTypeLoc TL, |
| 2850 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2851 | VectorType *T = TL.getTypePtr(); |
| 2852 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2853 | if (ElementType.isNull()) |
| 2854 | return QualType(); |
| 2855 | |
| 2856 | QualType Result = TL.getType(); |
| 2857 | if (getDerived().AlwaysRebuild() || |
| 2858 | ElementType != T->getElementType()) { |
| 2859 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2860 | T->getNumElements(), |
| 2861 | /*FIXME*/ SourceLocation()); |
| 2862 | if (Result.isNull()) |
| 2863 | return QualType(); |
| 2864 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2865 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2866 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2867 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2868 | |
| 2869 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2871 | |
| 2872 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2873 | ParmVarDecl * |
| 2874 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2875 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2876 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2877 | if (!NewDI) |
| 2878 | return 0; |
| 2879 | |
| 2880 | if (NewDI == OldDI) |
| 2881 | return OldParm; |
| 2882 | else |
| 2883 | return ParmVarDecl::Create(SemaRef.Context, |
| 2884 | OldParm->getDeclContext(), |
| 2885 | OldParm->getLocation(), |
| 2886 | OldParm->getIdentifier(), |
| 2887 | NewDI->getType(), |
| 2888 | NewDI, |
| 2889 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2890 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2891 | /* DefArg */ NULL); |
| 2892 | } |
| 2893 | |
| 2894 | template<typename Derived> |
| 2895 | bool TreeTransform<Derived>:: |
| 2896 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2897 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2898 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2899 | FunctionProtoType *T = TL.getTypePtr(); |
| 2900 | |
| 2901 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2902 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2903 | |
| 2904 | QualType NewType; |
| 2905 | ParmVarDecl *NewParm; |
| 2906 | |
| 2907 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2908 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2909 | if (!NewParm) |
| 2910 | return true; |
| 2911 | NewType = NewParm->getType(); |
| 2912 | |
| 2913 | // Deal with the possibility that we don't have a parameter |
| 2914 | // declaration for this parameter. |
| 2915 | } else { |
| 2916 | NewParm = 0; |
| 2917 | |
| 2918 | QualType OldType = T->getArgType(i); |
| 2919 | NewType = getDerived().TransformType(OldType); |
| 2920 | if (NewType.isNull()) |
| 2921 | return true; |
| 2922 | } |
| 2923 | |
| 2924 | PTypes.push_back(NewType); |
| 2925 | PVars.push_back(NewParm); |
| 2926 | } |
| 2927 | |
| 2928 | return false; |
| 2929 | } |
| 2930 | |
| 2931 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2932 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2933 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2934 | FunctionProtoTypeLoc TL, |
| 2935 | QualType ObjectType) { |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2936 | // Transform the parameters. We do this first for the benefit of template |
| 2937 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2938 | // instantiation scope before we transform the function type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2939 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2940 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2941 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2942 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2943 | |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2944 | FunctionProtoType *T = TL.getTypePtr(); |
| 2945 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2946 | if (ResultType.isNull()) |
| 2947 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2948 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2949 | QualType Result = TL.getType(); |
| 2950 | if (getDerived().AlwaysRebuild() || |
| 2951 | ResultType != T->getResultType() || |
| 2952 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2953 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2954 | ParamTypes.data(), |
| 2955 | ParamTypes.size(), |
| 2956 | T->isVariadic(), |
| 2957 | T->getTypeQuals()); |
| 2958 | if (Result.isNull()) |
| 2959 | return QualType(); |
| 2960 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2962 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2963 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2964 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2965 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2966 | NewTL.setArg(i, ParamDecls[i]); |
| 2967 | |
| 2968 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2969 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2970 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2971 | template<typename Derived> |
| 2972 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2973 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2974 | FunctionNoProtoTypeLoc TL, |
| 2975 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2976 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2977 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2978 | if (ResultType.isNull()) |
| 2979 | return QualType(); |
| 2980 | |
| 2981 | QualType Result = TL.getType(); |
| 2982 | if (getDerived().AlwaysRebuild() || |
| 2983 | ResultType != T->getResultType()) |
| 2984 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2985 | |
| 2986 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2987 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2988 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2989 | |
| 2990 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2993 | template<typename Derived> QualType |
| 2994 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2995 | UnresolvedUsingTypeLoc TL, |
| 2996 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2997 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2998 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2999 | if (!D) |
| 3000 | return QualType(); |
| 3001 | |
| 3002 | QualType Result = TL.getType(); |
| 3003 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 3004 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 3005 | if (Result.isNull()) |
| 3006 | return QualType(); |
| 3007 | } |
| 3008 | |
| 3009 | // We might get an arbitrary type spec type back. We should at |
| 3010 | // least always get a type spec type, though. |
| 3011 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 3012 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3013 | |
| 3014 | return Result; |
| 3015 | } |
| 3016 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3017 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3018 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3019 | TypedefTypeLoc TL, |
| 3020 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3021 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3022 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3023 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3024 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3025 | if (!Typedef) |
| 3026 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3028 | QualType Result = TL.getType(); |
| 3029 | if (getDerived().AlwaysRebuild() || |
| 3030 | Typedef != T->getDecl()) { |
| 3031 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3032 | if (Result.isNull()) |
| 3033 | return QualType(); |
| 3034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3036 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3037 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3038 | |
| 3039 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3040 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3041 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3042 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3043 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3044 | TypeOfExprTypeLoc TL, |
| 3045 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3046 | // typeof expressions are not potentially evaluated contexts |
| 3047 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3049 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3050 | if (E.isInvalid()) |
| 3051 | return QualType(); |
| 3052 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3053 | QualType Result = TL.getType(); |
| 3054 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3055 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3056 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3057 | if (Result.isNull()) |
| 3058 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3059 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3060 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3063 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3064 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3065 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3066 | |
| 3067 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3068 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3069 | |
| 3070 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3071 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3072 | TypeOfTypeLoc TL, |
| 3073 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3074 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3075 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3076 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3077 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3079 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3080 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3081 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3082 | if (Result.isNull()) |
| 3083 | return QualType(); |
| 3084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3085 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3086 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3087 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3088 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3089 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3090 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3091 | |
| 3092 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
| 3095 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3096 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3097 | DecltypeTypeLoc TL, |
| 3098 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3099 | DecltypeType *T = TL.getTypePtr(); |
| 3100 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3101 | // decltype expressions are not potentially evaluated contexts |
| 3102 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3104 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3105 | if (E.isInvalid()) |
| 3106 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3107 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3108 | QualType Result = TL.getType(); |
| 3109 | if (getDerived().AlwaysRebuild() || |
| 3110 | E.get() != T->getUnderlyingExpr()) { |
| 3111 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3112 | if (Result.isNull()) |
| 3113 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3114 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3115 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3116 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3117 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3118 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3119 | |
| 3120 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3124 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3125 | RecordTypeLoc TL, |
| 3126 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3127 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3128 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3129 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3130 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3131 | if (!Record) |
| 3132 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3134 | QualType Result = TL.getType(); |
| 3135 | if (getDerived().AlwaysRebuild() || |
| 3136 | Record != T->getDecl()) { |
| 3137 | Result = getDerived().RebuildRecordType(Record); |
| 3138 | if (Result.isNull()) |
| 3139 | return QualType(); |
| 3140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3141 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3142 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3143 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3144 | |
| 3145 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3147 | |
| 3148 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3149 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3150 | EnumTypeLoc TL, |
| 3151 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3152 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3153 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3154 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3155 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3156 | if (!Enum) |
| 3157 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3159 | QualType Result = TL.getType(); |
| 3160 | if (getDerived().AlwaysRebuild() || |
| 3161 | Enum != T->getDecl()) { |
| 3162 | Result = getDerived().RebuildEnumType(Enum); |
| 3163 | if (Result.isNull()) |
| 3164 | return QualType(); |
| 3165 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3167 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3168 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3169 | |
| 3170 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3171 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3172 | |
| 3173 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3174 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3175 | ElaboratedTypeLoc TL, |
| 3176 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3177 | ElaboratedType *T = TL.getTypePtr(); |
| 3178 | |
| 3179 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3180 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 3181 | if (Underlying.isNull()) |
| 3182 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3183 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3184 | QualType Result = TL.getType(); |
| 3185 | if (getDerived().AlwaysRebuild() || |
| 3186 | Underlying != T->getUnderlyingType()) { |
| 3187 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 3188 | if (Result.isNull()) |
| 3189 | return QualType(); |
| 3190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3192 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3193 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3194 | |
| 3195 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3196 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3198 | template<typename Derived> |
| 3199 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3200 | TypeLocBuilder &TLB, |
| 3201 | InjectedClassNameTypeLoc TL, |
| 3202 | QualType ObjectType) { |
| 3203 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3204 | TL.getTypePtr()->getDecl()); |
| 3205 | if (!D) return QualType(); |
| 3206 | |
| 3207 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3208 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3209 | return T; |
| 3210 | } |
| 3211 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3212 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3213 | template<typename Derived> |
| 3214 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3215 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3216 | TemplateTypeParmTypeLoc TL, |
| 3217 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3218 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3221 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3222 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3223 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3224 | SubstTemplateTypeParmTypeLoc TL, |
| 3225 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3226 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3230 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3231 | const TemplateSpecializationType *TST, |
| 3232 | QualType ObjectType) { |
| 3233 | // FIXME: this entire method is a temporary workaround; callers |
| 3234 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3235 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3236 | // Fake up a TemplateSpecializationTypeLoc. |
| 3237 | TypeLocBuilder TLB; |
| 3238 | TemplateSpecializationTypeLoc TL |
| 3239 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3240 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3241 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3242 | |
| 3243 | TL.setTemplateNameLoc(BaseLoc); |
| 3244 | TL.setLAngleLoc(BaseLoc); |
| 3245 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3246 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3247 | const TemplateArgument &TA = TST->getArg(i); |
| 3248 | TemplateArgumentLoc TAL; |
| 3249 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3250 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3251 | } |
| 3252 | |
| 3253 | TypeLocBuilder IgnoredTLB; |
| 3254 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3255 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3256 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3257 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3258 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3259 | TypeLocBuilder &TLB, |
| 3260 | TemplateSpecializationTypeLoc TL, |
| 3261 | QualType ObjectType) { |
| 3262 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3263 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3264 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3265 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3266 | if (Template.isNull()) |
| 3267 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3269 | TemplateArgumentListInfo NewTemplateArgs; |
| 3270 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3271 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3272 | |
| 3273 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3274 | TemplateArgumentLoc Loc; |
| 3275 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3276 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3277 | NewTemplateArgs.addArgument(Loc); |
| 3278 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3280 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3281 | |
| 3282 | QualType Result = |
| 3283 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3284 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3285 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3286 | |
| 3287 | if (!Result.isNull()) { |
| 3288 | TemplateSpecializationTypeLoc NewTL |
| 3289 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3290 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3291 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3292 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3293 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3294 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3295 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3296 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3297 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3298 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | |
| 3300 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3301 | QualType |
| 3302 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3303 | QualifiedNameTypeLoc TL, |
| 3304 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3305 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3306 | NestedNameSpecifier *NNS |
| 3307 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3308 | SourceRange(), |
| 3309 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3310 | if (!NNS) |
| 3311 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3313 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 3314 | if (Named.isNull()) |
| 3315 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3317 | QualType Result = TL.getType(); |
| 3318 | if (getDerived().AlwaysRebuild() || |
| 3319 | NNS != T->getQualifier() || |
| 3320 | Named != T->getNamedType()) { |
| 3321 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 3322 | if (Result.isNull()) |
| 3323 | return QualType(); |
| 3324 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3325 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3326 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 3327 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3328 | |
| 3329 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3331 | |
| 3332 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3333 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3334 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3335 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3336 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3337 | |
| 3338 | /* FIXME: preserve source information better than this */ |
| 3339 | SourceRange SR(TL.getNameLoc()); |
| 3340 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3341 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3342 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3343 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3344 | if (!NNS) |
| 3345 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3347 | QualType Result; |
| 3348 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3349 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3351 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 3352 | if (NewTemplateId.isNull()) |
| 3353 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3354 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3355 | if (!getDerived().AlwaysRebuild() && |
| 3356 | NNS == T->getQualifier() && |
| 3357 | NewTemplateId == QualType(TemplateId, 0)) |
| 3358 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3360 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3361 | NewTemplateId); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3362 | } else { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3363 | Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 3364 | T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3365 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3366 | if (Result.isNull()) |
| 3367 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3368 | |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3369 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3370 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3371 | |
| 3372 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3373 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3375 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3376 | QualType |
| 3377 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3378 | ObjCInterfaceTypeLoc TL, |
| 3379 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3380 | // ObjCInterfaceType is never dependent. |
| 3381 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | |
| 3384 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3385 | QualType |
| 3386 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3387 | ObjCObjectPointerTypeLoc TL, |
| 3388 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3389 | // ObjCObjectPointerType is never dependent. |
| 3390 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3393 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3394 | // Statement transformation |
| 3395 | //===----------------------------------------------------------------------===// |
| 3396 | template<typename Derived> |
| 3397 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3398 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3399 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | template<typename Derived> |
| 3403 | Sema::OwningStmtResult |
| 3404 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3405 | return getDerived().TransformCompoundStmt(S, false); |
| 3406 | } |
| 3407 | |
| 3408 | template<typename Derived> |
| 3409 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3411 | bool IsStmtExpr) { |
| 3412 | bool SubStmtChanged = false; |
| 3413 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3414 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3415 | B != BEnd; ++B) { |
| 3416 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3417 | if (Result.isInvalid()) |
| 3418 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3420 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3421 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3422 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3423 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3424 | if (!getDerived().AlwaysRebuild() && |
| 3425 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3426 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3427 | |
| 3428 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3429 | move_arg(Statements), |
| 3430 | S->getRBracLoc(), |
| 3431 | IsStmtExpr); |
| 3432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3433 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | template<typename Derived> |
| 3435 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3436 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3437 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3438 | { |
| 3439 | // The case value expressions are not potentially evaluated. |
| 3440 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3442 | // Transform the left-hand case value. |
| 3443 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3444 | if (LHS.isInvalid()) |
| 3445 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3447 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3448 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3449 | if (RHS.isInvalid()) |
| 3450 | return SemaRef.StmtError(); |
| 3451 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3453 | // Build the case statement. |
| 3454 | // Case statements are always rebuilt so that they will attached to their |
| 3455 | // transformed switch statement. |
| 3456 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3457 | move(LHS), |
| 3458 | S->getEllipsisLoc(), |
| 3459 | move(RHS), |
| 3460 | S->getColonLoc()); |
| 3461 | if (Case.isInvalid()) |
| 3462 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3464 | // Transform the statement following the case |
| 3465 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3466 | if (SubStmt.isInvalid()) |
| 3467 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3468 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3469 | // Attach the body to the case statement |
| 3470 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3471 | } |
| 3472 | |
| 3473 | template<typename Derived> |
| 3474 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3475 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3476 | // Transform the statement following the default case |
| 3477 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3478 | if (SubStmt.isInvalid()) |
| 3479 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3481 | // Default statements are always rebuilt |
| 3482 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3483 | move(SubStmt)); |
| 3484 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3485 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3486 | template<typename Derived> |
| 3487 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3489 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3490 | if (SubStmt.isInvalid()) |
| 3491 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3492 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3493 | // FIXME: Pass the real colon location in. |
| 3494 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3495 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3496 | move(SubStmt)); |
| 3497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3499 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | Sema::OwningStmtResult |
| 3501 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3502 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3503 | OwningExprResult Cond(SemaRef); |
| 3504 | VarDecl *ConditionVar = 0; |
| 3505 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3506 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3507 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3508 | getDerived().TransformDefinition( |
| 3509 | S->getConditionVariable()->getLocation(), |
| 3510 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3511 | if (!ConditionVar) |
| 3512 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3513 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3514 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3515 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3516 | if (Cond.isInvalid()) |
| 3517 | return SemaRef.StmtError(); |
| 3518 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3519 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3520 | // Transform the "then" branch. |
| 3521 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3522 | if (Then.isInvalid()) |
| 3523 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3524 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3525 | // Transform the "else" branch. |
| 3526 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3527 | if (Else.isInvalid()) |
| 3528 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3529 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3530 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 3531 | Cond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3532 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3533 | Then.get() == S->getThen() && |
| 3534 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | return SemaRef.Owned(S->Retain()); |
| 3536 | |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 3537 | return getDerived().RebuildIfStmt(S->getIfLoc(), move(Cond), ConditionVar, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3538 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | template<typename Derived> |
| 3543 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3546 | OwningExprResult Cond(SemaRef); |
| 3547 | VarDecl *ConditionVar = 0; |
| 3548 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3549 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3550 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3551 | getDerived().TransformDefinition( |
| 3552 | S->getConditionVariable()->getLocation(), |
| 3553 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3554 | if (!ConditionVar) |
| 3555 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3556 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3557 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3558 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3559 | if (Cond.isInvalid()) |
| 3560 | return SemaRef.StmtError(); |
| 3561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3562 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3563 | // Rebuild the switch statement. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 3564 | OwningStmtResult Switch |
| 3565 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3566 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3567 | if (Switch.isInvalid()) |
| 3568 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3570 | // Transform the body of the switch statement. |
| 3571 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3572 | if (Body.isInvalid()) |
| 3573 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3575 | // Complete the switch statement. |
| 3576 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3577 | move(Body)); |
| 3578 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3580 | template<typename Derived> |
| 3581 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3583 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3584 | OwningExprResult Cond(SemaRef); |
| 3585 | VarDecl *ConditionVar = 0; |
| 3586 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3587 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3588 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3589 | getDerived().TransformDefinition( |
| 3590 | S->getConditionVariable()->getLocation(), |
| 3591 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3592 | if (!ConditionVar) |
| 3593 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3594 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3595 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3596 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3597 | if (Cond.isInvalid()) |
| 3598 | return SemaRef.StmtError(); |
| 3599 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3600 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3601 | // Transform the body |
| 3602 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3603 | if (Body.isInvalid()) |
| 3604 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3606 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 3607 | Cond.get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3608 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 3612 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), move(Cond), |
| 3613 | ConditionVar, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3614 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3616 | template<typename Derived> |
| 3617 | Sema::OwningStmtResult |
| 3618 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3619 | // Transform the condition |
| 3620 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3621 | if (Cond.isInvalid()) |
| 3622 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3623 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3624 | // Transform the body |
| 3625 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3626 | if (Body.isInvalid()) |
| 3627 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3629 | if (!getDerived().AlwaysRebuild() && |
| 3630 | Cond.get() == S->getCond() && |
| 3631 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | return SemaRef.Owned(S->Retain()); |
| 3633 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3634 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3635 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3636 | S->getRParenLoc()); |
| 3637 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3638 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3639 | template<typename Derived> |
| 3640 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3641 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3642 | // Transform the initialization statement |
| 3643 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3644 | if (Init.isInvalid()) |
| 3645 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3647 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3648 | OwningExprResult Cond(SemaRef); |
| 3649 | VarDecl *ConditionVar = 0; |
| 3650 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3651 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3652 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3653 | getDerived().TransformDefinition( |
| 3654 | S->getConditionVariable()->getLocation(), |
| 3655 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3656 | if (!ConditionVar) |
| 3657 | return SemaRef.StmtError(); |
| 3658 | } else { |
| 3659 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3660 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3661 | if (Cond.isInvalid()) |
| 3662 | return SemaRef.StmtError(); |
| 3663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3664 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3665 | // Transform the increment |
| 3666 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3667 | if (Inc.isInvalid()) |
| 3668 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3670 | // Transform the body |
| 3671 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3672 | if (Body.isInvalid()) |
| 3673 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3674 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3675 | if (!getDerived().AlwaysRebuild() && |
| 3676 | Init.get() == S->getInit() && |
| 3677 | Cond.get() == S->getCond() && |
| 3678 | Inc.get() == S->getInc() && |
| 3679 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | return SemaRef.Owned(S->Retain()); |
| 3681 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3682 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame^] | 3683 | move(Init), move(Cond), ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3684 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3685 | S->getRParenLoc(), move(Body)); |
| 3686 | } |
| 3687 | |
| 3688 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | Sema::OwningStmtResult |
| 3690 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3691 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3693 | S->getLabel()); |
| 3694 | } |
| 3695 | |
| 3696 | template<typename Derived> |
| 3697 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3698 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3699 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3700 | if (Target.isInvalid()) |
| 3701 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3703 | if (!getDerived().AlwaysRebuild() && |
| 3704 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3706 | |
| 3707 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3708 | move(Target)); |
| 3709 | } |
| 3710 | |
| 3711 | template<typename Derived> |
| 3712 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3714 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3715 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3716 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3717 | template<typename Derived> |
| 3718 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3719 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3720 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3721 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3722 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3723 | template<typename Derived> |
| 3724 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3726 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3727 | if (Result.isInvalid()) |
| 3728 | return SemaRef.StmtError(); |
| 3729 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3731 | // to tell whether the return type of the function has changed. |
| 3732 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3733 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3734 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3735 | template<typename Derived> |
| 3736 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3737 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3738 | bool DeclChanged = false; |
| 3739 | llvm::SmallVector<Decl *, 4> Decls; |
| 3740 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3741 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3742 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3743 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3744 | if (!Transformed) |
| 3745 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3746 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3747 | if (Transformed != *D) |
| 3748 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3750 | Decls.push_back(Transformed); |
| 3751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3753 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3754 | return SemaRef.Owned(S->Retain()); |
| 3755 | |
| 3756 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3757 | S->getStartLoc(), S->getEndLoc()); |
| 3758 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3759 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3760 | template<typename Derived> |
| 3761 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3762 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3763 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | template<typename Derived> |
| 3768 | Sema::OwningStmtResult |
| 3769 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3770 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3771 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3772 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3773 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3774 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3775 | OwningExprResult AsmString(SemaRef); |
| 3776 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3777 | |
| 3778 | bool ExprsChanged = false; |
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 | // Go through the outputs. |
| 3781 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3782 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3783 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3784 | // No need to transform the constraint literal. |
| 3785 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3786 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3787 | // Transform the output expr. |
| 3788 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3789 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3790 | if (Result.isInvalid()) |
| 3791 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3792 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3793 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3794 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3795 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3796 | } |
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 | // Go through the inputs. |
| 3799 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3800 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3801 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3802 | // No need to transform the constraint literal. |
| 3803 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3804 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3805 | // Transform the input expr. |
| 3806 | Expr *InputExpr = S->getInputExpr(I); |
| 3807 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3808 | if (Result.isInvalid()) |
| 3809 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3810 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3811 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3812 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3813 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3814 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3815 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3816 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3817 | return SemaRef.Owned(S->Retain()); |
| 3818 | |
| 3819 | // Go through the clobbers. |
| 3820 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3821 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3822 | |
| 3823 | // No need to transform the asm string literal. |
| 3824 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3825 | |
| 3826 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3827 | S->isSimple(), |
| 3828 | S->isVolatile(), |
| 3829 | S->getNumOutputs(), |
| 3830 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3831 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3832 | move_arg(Constraints), |
| 3833 | move_arg(Exprs), |
| 3834 | move(AsmString), |
| 3835 | move_arg(Clobbers), |
| 3836 | S->getRParenLoc(), |
| 3837 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | |
| 3841 | template<typename Derived> |
| 3842 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3843 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3844 | // Transform the body of the @try. |
| 3845 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3846 | if (TryBody.isInvalid()) |
| 3847 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3849 | // Transform the @catch statements (if present). |
| 3850 | bool AnyCatchChanged = false; |
| 3851 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3852 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3853 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3854 | if (Catch.isInvalid()) |
| 3855 | return SemaRef.StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3856 | if (Catch.get() != S->getCatchStmt(I)) |
| 3857 | AnyCatchChanged = true; |
| 3858 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3859 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3860 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3861 | // Transform the @finally statement (if present). |
| 3862 | OwningStmtResult Finally(SemaRef); |
| 3863 | if (S->getFinallyStmt()) { |
| 3864 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3865 | if (Finally.isInvalid()) |
| 3866 | return SemaRef.StmtError(); |
| 3867 | } |
| 3868 | |
| 3869 | // If nothing changed, just retain this statement. |
| 3870 | if (!getDerived().AlwaysRebuild() && |
| 3871 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3872 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3873 | Finally.get() == S->getFinallyStmt()) |
| 3874 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3876 | // Build a new statement. |
| 3877 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3878 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3879 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3880 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3881 | template<typename Derived> |
| 3882 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3884 | // Transform the @catch parameter, if there is one. |
| 3885 | VarDecl *Var = 0; |
| 3886 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3887 | TypeSourceInfo *TSInfo = 0; |
| 3888 | if (FromVar->getTypeSourceInfo()) { |
| 3889 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3890 | if (!TSInfo) |
| 3891 | return SemaRef.StmtError(); |
| 3892 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3894 | QualType T; |
| 3895 | if (TSInfo) |
| 3896 | T = TSInfo->getType(); |
| 3897 | else { |
| 3898 | T = getDerived().TransformType(FromVar->getType()); |
| 3899 | if (T.isNull()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3900 | return SemaRef.StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3901 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3902 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3903 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 3904 | if (!Var) |
| 3905 | return SemaRef.StmtError(); |
| 3906 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3907 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3908 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 3909 | if (Body.isInvalid()) |
| 3910 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3911 | |
| 3912 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3913 | S->getRParenLoc(), |
| 3914 | Var, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3915 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3916 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3917 | template<typename Derived> |
| 3918 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3920 | // Transform the body. |
| 3921 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 3922 | if (Body.isInvalid()) |
| 3923 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3924 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3925 | // If nothing changed, just retain this statement. |
| 3926 | if (!getDerived().AlwaysRebuild() && |
| 3927 | Body.get() == S->getFinallyBody()) |
| 3928 | return SemaRef.Owned(S->Retain()); |
| 3929 | |
| 3930 | // Build a new statement. |
| 3931 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 3932 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3933 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3934 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3935 | template<typename Derived> |
| 3936 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3938 | OwningExprResult Operand(SemaRef); |
| 3939 | if (S->getThrowExpr()) { |
| 3940 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 3941 | if (Operand.isInvalid()) |
| 3942 | return getSema().StmtError(); |
| 3943 | } |
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 | if (!getDerived().AlwaysRebuild() && |
| 3946 | Operand.get() == S->getThrowExpr()) |
| 3947 | return getSema().Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3948 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 3949 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3950 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3951 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3952 | template<typename Derived> |
| 3953 | Sema::OwningStmtResult |
| 3954 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3956 | // Transform the object we are locking. |
| 3957 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 3958 | if (Object.isInvalid()) |
| 3959 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3961 | // Transform the body. |
| 3962 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 3963 | if (Body.isInvalid()) |
| 3964 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3965 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 3966 | // If nothing change, just retain the current statement. |
| 3967 | if (!getDerived().AlwaysRebuild() && |
| 3968 | Object.get() == S->getSynchExpr() && |
| 3969 | Body.get() == S->getSynchBody()) |
| 3970 | return SemaRef.Owned(S->Retain()); |
| 3971 | |
| 3972 | // Build a new statement. |
| 3973 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 3974 | move(Object), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | template<typename Derived> |
| 3978 | Sema::OwningStmtResult |
| 3979 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3981 | // Transform the element statement. |
| 3982 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 3983 | if (Element.isInvalid()) |
| 3984 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3985 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3986 | // Transform the collection expression. |
| 3987 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 3988 | if (Collection.isInvalid()) |
| 3989 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3990 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3991 | // Transform the body. |
| 3992 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3993 | if (Body.isInvalid()) |
| 3994 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3995 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 3996 | // If nothing changed, just retain this statement. |
| 3997 | if (!getDerived().AlwaysRebuild() && |
| 3998 | Element.get() == S->getElement() && |
| 3999 | Collection.get() == S->getCollection() && |
| 4000 | Body.get() == S->getBody()) |
| 4001 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4002 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4003 | // Build a new statement. |
| 4004 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4005 | /*FIXME:*/S->getForLoc(), |
| 4006 | move(Element), |
| 4007 | move(Collection), |
| 4008 | S->getRParenLoc(), |
| 4009 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | |
| 4013 | template<typename Derived> |
| 4014 | Sema::OwningStmtResult |
| 4015 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4016 | // Transform the exception declaration, if any. |
| 4017 | VarDecl *Var = 0; |
| 4018 | if (S->getExceptionDecl()) { |
| 4019 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4020 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4021 | ExceptionDecl->getDeclName()); |
| 4022 | |
| 4023 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4024 | if (T.isNull()) |
| 4025 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4026 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4027 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4028 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4029 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4030 | ExceptionDecl->getIdentifier(), |
| 4031 | ExceptionDecl->getLocation(), |
| 4032 | /*FIXME: Inaccurate*/ |
| 4033 | SourceRange(ExceptionDecl->getLocation())); |
| 4034 | if (!Var || Var->isInvalidDecl()) { |
| 4035 | if (Var) |
| 4036 | Var->Destroy(SemaRef.Context); |
| 4037 | return SemaRef.StmtError(); |
| 4038 | } |
| 4039 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4041 | // Transform the actual exception handler. |
| 4042 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 4043 | if (Handler.isInvalid()) { |
| 4044 | if (Var) |
| 4045 | Var->Destroy(SemaRef.Context); |
| 4046 | return SemaRef.StmtError(); |
| 4047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4048 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4049 | if (!getDerived().AlwaysRebuild() && |
| 4050 | !Var && |
| 4051 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4052 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4053 | |
| 4054 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4055 | Var, |
| 4056 | move(Handler)); |
| 4057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4059 | template<typename Derived> |
| 4060 | Sema::OwningStmtResult |
| 4061 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4062 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4064 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4065 | if (TryBlock.isInvalid()) |
| 4066 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4067 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4068 | // Transform the handlers. |
| 4069 | bool HandlerChanged = false; |
| 4070 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4071 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4072 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4073 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4074 | if (Handler.isInvalid()) |
| 4075 | return SemaRef.StmtError(); |
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 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4078 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4079 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4080 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4081 | if (!getDerived().AlwaysRebuild() && |
| 4082 | TryBlock.get() == S->getTryBlock() && |
| 4083 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4084 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4085 | |
| 4086 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4088 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4090 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | // Expression transformation |
| 4092 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4093 | template<typename Derived> |
| 4094 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4095 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4098 | |
| 4099 | template<typename Derived> |
| 4100 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4101 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4102 | NestedNameSpecifier *Qualifier = 0; |
| 4103 | if (E->getQualifier()) { |
| 4104 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4105 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4106 | if (!Qualifier) |
| 4107 | return SemaRef.ExprError(); |
| 4108 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4109 | |
| 4110 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4111 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4112 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4113 | if (!ND) |
| 4114 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4115 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4116 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4117 | Qualifier == E->getQualifier() && |
| 4118 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4119 | !E->hasExplicitTemplateArgumentList()) { |
| 4120 | |
| 4121 | // Mark it referenced in the new context regardless. |
| 4122 | // FIXME: this is a bit instantiation-specific. |
| 4123 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4124 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4126 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4127 | |
| 4128 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 4129 | if (E->hasExplicitTemplateArgumentList()) { |
| 4130 | TemplateArgs = &TransArgs; |
| 4131 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4132 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4133 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4134 | TemplateArgumentLoc Loc; |
| 4135 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4136 | return SemaRef.ExprError(); |
| 4137 | TransArgs.addArgument(Loc); |
| 4138 | } |
| 4139 | } |
| 4140 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4141 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4142 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4143 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4144 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4145 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4146 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4147 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4148 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4149 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4153 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4154 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4156 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4157 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4159 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4161 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4163 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4164 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4165 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4166 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4169 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4170 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4171 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4172 | return SemaRef.Owned(E->Retain()); |
| 4173 | } |
| 4174 | |
| 4175 | template<typename Derived> |
| 4176 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4177 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4178 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4179 | if (SubExpr.isInvalid()) |
| 4180 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | return SemaRef.Owned(E->Retain()); |
| 4184 | |
| 4185 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4186 | E->getRParen()); |
| 4187 | } |
| 4188 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | template<typename Derived> |
| 4190 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4191 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4192 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | if (SubExpr.isInvalid()) |
| 4194 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | return SemaRef.Owned(E->Retain()); |
| 4198 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4199 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4200 | E->getOpcode(), |
| 4201 | move(SubExpr)); |
| 4202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4204 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | Sema::OwningExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4206 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4207 | // Transform the type. |
| 4208 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4209 | if (!Type) |
| 4210 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4211 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4212 | // Transform all of the components into components similar to what the |
| 4213 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4214 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4215 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4216 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4217 | // template code that we don't care. |
| 4218 | bool ExprChanged = false; |
| 4219 | typedef Action::OffsetOfComponent Component; |
| 4220 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4221 | llvm::SmallVector<Component, 4> Components; |
| 4222 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4223 | const Node &ON = E->getComponent(I); |
| 4224 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4225 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4226 | Comp.LocStart = ON.getRange().getBegin(); |
| 4227 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4228 | switch (ON.getKind()) { |
| 4229 | case Node::Array: { |
| 4230 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4231 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4232 | if (Index.isInvalid()) |
| 4233 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4234 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4235 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4236 | Comp.isBrackets = true; |
| 4237 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4238 | break; |
| 4239 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4241 | case Node::Field: |
| 4242 | case Node::Identifier: |
| 4243 | Comp.isBrackets = false; |
| 4244 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4245 | if (!Comp.U.IdentInfo) |
| 4246 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4247 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4248 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4249 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4250 | case Node::Base: |
| 4251 | // Will be recomputed during the rebuild. |
| 4252 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4253 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4254 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4255 | Components.push_back(Comp); |
| 4256 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4257 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4258 | // If nothing changed, retain the existing expression. |
| 4259 | if (!getDerived().AlwaysRebuild() && |
| 4260 | Type == E->getTypeSourceInfo() && |
| 4261 | !ExprChanged) |
| 4262 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4263 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4264 | // Build a new offsetof expression. |
| 4265 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4266 | Components.data(), Components.size(), |
| 4267 | E->getRParenLoc()); |
| 4268 | } |
| 4269 | |
| 4270 | template<typename Derived> |
| 4271 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4272 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4273 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4274 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4275 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4276 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4277 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4280 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4282 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4283 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | E->getSourceRange()); |
| 4286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4287 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4288 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4289 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4290 | // C++0x [expr.sizeof]p1: |
| 4291 | // The operand is either an expression, which is an unevaluated operand |
| 4292 | // [...] |
| 4293 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
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 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4296 | if (SubExpr.isInvalid()) |
| 4297 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4300 | return SemaRef.Owned(E->Retain()); |
| 4301 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4302 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4303 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4304 | E->isSizeOf(), |
| 4305 | E->getSourceRange()); |
| 4306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4308 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4309 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4310 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4311 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4312 | if (LHS.isInvalid()) |
| 4313 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4315 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4316 | if (RHS.isInvalid()) |
| 4317 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
| 4319 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4320 | if (!getDerived().AlwaysRebuild() && |
| 4321 | LHS.get() == E->getLHS() && |
| 4322 | RHS.get() == E->getRHS()) |
| 4323 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4325 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4326 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4327 | move(RHS), |
| 4328 | E->getRBracketLoc()); |
| 4329 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
| 4331 | template<typename Derived> |
| 4332 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4333 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4334 | // Transform the callee. |
| 4335 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4336 | if (Callee.isInvalid()) |
| 4337 | return SemaRef.ExprError(); |
| 4338 | |
| 4339 | // Transform arguments. |
| 4340 | bool ArgChanged = false; |
| 4341 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4342 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4343 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4344 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4345 | if (Arg.isInvalid()) |
| 4346 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | // FIXME: Wrong source location information for the ','. |
| 4349 | FakeCommaLocs.push_back( |
| 4350 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | |
| 4352 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4353 | Args.push_back(Arg.takeAs<Expr>()); |
| 4354 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | if (!getDerived().AlwaysRebuild() && |
| 4357 | Callee.get() == E->getCallee() && |
| 4358 | !ArgChanged) |
| 4359 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4360 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4361 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4362 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4363 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4364 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4365 | move_arg(Args), |
| 4366 | FakeCommaLocs.data(), |
| 4367 | E->getRParenLoc()); |
| 4368 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | |
| 4370 | template<typename Derived> |
| 4371 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4372 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4373 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4374 | if (Base.isInvalid()) |
| 4375 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4376 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4377 | NestedNameSpecifier *Qualifier = 0; |
| 4378 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4379 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4380 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4381 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4382 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4383 | return SemaRef.ExprError(); |
| 4384 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4386 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4387 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4388 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | if (!Member) |
| 4390 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4392 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4393 | if (FoundDecl == E->getMemberDecl()) { |
| 4394 | FoundDecl = Member; |
| 4395 | } else { |
| 4396 | FoundDecl = cast_or_null<NamedDecl>( |
| 4397 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4398 | if (!FoundDecl) |
| 4399 | return SemaRef.ExprError(); |
| 4400 | } |
| 4401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | if (!getDerived().AlwaysRebuild() && |
| 4403 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4404 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4405 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4406 | FoundDecl == E->getFoundDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4407 | !E->hasExplicitTemplateArgumentList()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4408 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4409 | // Mark it referenced in the new context regardless. |
| 4410 | // FIXME: this is a bit instantiation-specific. |
| 4411 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4413 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4415 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4416 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4417 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4418 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4419 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4420 | TemplateArgumentLoc Loc; |
| 4421 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4422 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4423 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4424 | } |
| 4425 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | // FIXME: Bogus source location for the operator |
| 4428 | SourceLocation FakeOperatorLoc |
| 4429 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4430 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4431 | // FIXME: to do this check properly, we will need to preserve the |
| 4432 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4433 | // base (and therefore couldn't do the check) and a |
| 4434 | // nested-name-qualifier (and therefore could do the lookup). |
| 4435 | NamedDecl *FirstQualifierInScope = 0; |
| 4436 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4438 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4439 | Qualifier, |
| 4440 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4441 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4442 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4443 | FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4444 | (E->hasExplicitTemplateArgumentList() |
| 4445 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4446 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4448 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4449 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4450 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4451 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4453 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4457 | if (RHS.isInvalid()) |
| 4458 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4459 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | if (!getDerived().AlwaysRebuild() && |
| 4461 | LHS.get() == E->getLHS() && |
| 4462 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4463 | return SemaRef.Owned(E->Retain()); |
| 4464 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4465 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4466 | move(LHS), move(RHS)); |
| 4467 | } |
| 4468 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | Sema::OwningExprResult |
| 4471 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4472 | CompoundAssignOperator *E) { |
| 4473 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4475 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4476 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4477 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4478 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4480 | if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS()); |
| 4484 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4488 | if (RHS.isInvalid()) |
| 4489 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | if (!getDerived().AlwaysRebuild() && |
| 4492 | Cond.get() == E->getCond() && |
| 4493 | LHS.get() == E->getLHS() && |
| 4494 | RHS.get() == E->getRHS()) |
| 4495 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | |
| 4497 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4498 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4499 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4500 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | move(RHS)); |
| 4502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | |
| 4504 | template<typename Derived> |
| 4505 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4506 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4507 | // Implicit casts are eliminated during transformation, since they |
| 4508 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4509 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4512 | template<typename Derived> |
| 4513 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4514 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4515 | TypeSourceInfo *OldT; |
| 4516 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4517 | { |
| 4518 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4521 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4522 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4523 | OldT = E->getTypeInfoAsWritten(); |
| 4524 | NewT = getDerived().TransformType(OldT); |
| 4525 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | return SemaRef.ExprError(); |
| 4527 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4528 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4529 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4530 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4531 | if (SubExpr.isInvalid()) |
| 4532 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4535 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4536 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4537 | return SemaRef.Owned(E->Retain()); |
| 4538 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4539 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4540 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4541 | E->getRParenLoc(), |
| 4542 | move(SubExpr)); |
| 4543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4544 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4545 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4546 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4547 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4548 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4549 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4550 | if (!NewT) |
| 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 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4554 | if (Init.isInvalid()) |
| 4555 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4558 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4562 | // Note: the expression type doesn't necessarily match the |
| 4563 | // type-as-written, but that's okay, because it should always be |
| 4564 | // derivable from the initializer. |
| 4565 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4566 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4568 | move(Init)); |
| 4569 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4571 | template<typename Derived> |
| 4572 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4573 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4575 | if (Base.isInvalid()) |
| 4576 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4577 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4578 | if (!getDerived().AlwaysRebuild() && |
| 4579 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | return SemaRef.Owned(E->Retain()); |
| 4581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4585 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4586 | E->getAccessorLoc(), |
| 4587 | E->getAccessor()); |
| 4588 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4589 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4590 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4591 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4592 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4593 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4594 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4595 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4596 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4597 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4598 | if (Init.isInvalid()) |
| 4599 | return SemaRef.ExprError(); |
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 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4602 | Inits.push_back(Init.takeAs<Expr>()); |
| 4603 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4605 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | return SemaRef.Owned(E->Retain()); |
| 4607 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4608 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4609 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4611 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4612 | template<typename Derived> |
| 4613 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4614 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4617 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4618 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4619 | if (Init.isInvalid()) |
| 4620 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4622 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4623 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4624 | bool ExprChanged = false; |
| 4625 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4626 | DEnd = E->designators_end(); |
| 4627 | D != DEnd; ++D) { |
| 4628 | if (D->isFieldDesignator()) { |
| 4629 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4630 | D->getDotLoc(), |
| 4631 | D->getFieldLoc())); |
| 4632 | continue; |
| 4633 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4635 | if (D->isArrayDesignator()) { |
| 4636 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4637 | if (Index.isInvalid()) |
| 4638 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | |
| 4640 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4642 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4644 | ArrayExprs.push_back(Index.release()); |
| 4645 | continue; |
| 4646 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4648 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4650 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4651 | if (Start.isInvalid()) |
| 4652 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4654 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4655 | if (End.isInvalid()) |
| 4656 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | |
| 4658 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | End.get(), |
| 4660 | D->getLBracketLoc(), |
| 4661 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4663 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4664 | End.get() != E->getArrayRangeEnd(*D); |
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 | ArrayExprs.push_back(Start.release()); |
| 4667 | ArrayExprs.push_back(End.release()); |
| 4668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4669 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4670 | if (!getDerived().AlwaysRebuild() && |
| 4671 | Init.get() == E->getInit() && |
| 4672 | !ExprChanged) |
| 4673 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4675 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4676 | E->getEqualOrColonLoc(), |
| 4677 | E->usesGNUSyntax(), move(Init)); |
| 4678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4681 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4682 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4683 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4684 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4685 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4686 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4687 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4688 | QualType T = getDerived().TransformType(E->getType()); |
| 4689 | if (T.isNull()) |
| 4690 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4692 | if (!getDerived().AlwaysRebuild() && |
| 4693 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | return SemaRef.Owned(E->Retain()); |
| 4695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4696 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4697 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4699 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4701 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | // FIXME: Do we want the type as written? |
| 4703 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4705 | { |
| 4706 | // FIXME: Source location isn't quite accurate. |
| 4707 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4708 | T = getDerived().TransformType(E->getType()); |
| 4709 | if (T.isNull()) |
| 4710 | return SemaRef.ExprError(); |
| 4711 | } |
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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4714 | if (SubExpr.isInvalid()) |
| 4715 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4716 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4717 | if (!getDerived().AlwaysRebuild() && |
| 4718 | T == E->getType() && |
| 4719 | SubExpr.get() == E->getSubExpr()) |
| 4720 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4723 | T, E->getRParenLoc()); |
| 4724 | } |
| 4725 | |
| 4726 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4728 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4729 | bool ArgumentChanged = false; |
| 4730 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4731 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4732 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4733 | if (Init.isInvalid()) |
| 4734 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4737 | Inits.push_back(Init.takeAs<Expr>()); |
| 4738 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4739 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4740 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4741 | move_arg(Inits), |
| 4742 | E->getRParenLoc()); |
| 4743 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4745 | /// \brief Transform an address-of-label expression. |
| 4746 | /// |
| 4747 | /// By default, the transformation of an address-of-label expression always |
| 4748 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4749 | /// the corresponding label statement by semantic analysis. |
| 4750 | template<typename Derived> |
| 4751 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4752 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4753 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4754 | E->getLabel()); |
| 4755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4756 | |
| 4757 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4758 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4759 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4761 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4762 | if (SubStmt.isInvalid()) |
| 4763 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4765 | if (!getDerived().AlwaysRebuild() && |
| 4766 | SubStmt.get() == E->getSubStmt()) |
| 4767 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4768 | |
| 4769 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4770 | move(SubStmt), |
| 4771 | E->getRParenLoc()); |
| 4772 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4774 | template<typename Derived> |
| 4775 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4776 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4777 | QualType T1, T2; |
| 4778 | { |
| 4779 | // FIXME: Source location isn't quite accurate. |
| 4780 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
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 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4783 | if (T1.isNull()) |
| 4784 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4785 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4786 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4787 | if (T2.isNull()) |
| 4788 | return SemaRef.ExprError(); |
| 4789 | } |
| 4790 | |
| 4791 | if (!getDerived().AlwaysRebuild() && |
| 4792 | T1 == E->getArgType1() && |
| 4793 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | return SemaRef.Owned(E->Retain()); |
| 4795 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4796 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4797 | T1, T2, E->getRParenLoc()); |
| 4798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4799 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | template<typename Derived> |
| 4801 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4802 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4803 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4804 | if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS()); |
| 4808 | if (LHS.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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4812 | if (RHS.isInvalid()) |
| 4813 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4815 | if (!getDerived().AlwaysRebuild() && |
| 4816 | Cond.get() == E->getCond() && |
| 4817 | LHS.get() == E->getLHS() && |
| 4818 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4819 | return SemaRef.Owned(E->Retain()); |
| 4820 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4821 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4822 | move(Cond), move(LHS), move(RHS), |
| 4823 | E->getRParenLoc()); |
| 4824 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4826 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4828 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | template<typename Derived> |
| 4833 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4834 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4835 | switch (E->getOperator()) { |
| 4836 | case OO_New: |
| 4837 | case OO_Delete: |
| 4838 | case OO_Array_New: |
| 4839 | case OO_Array_Delete: |
| 4840 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4841 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4842 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4843 | case OO_Call: { |
| 4844 | // This is a call to an object's operator(). |
| 4845 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4846 | |
| 4847 | // Transform the object itself. |
| 4848 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4849 | if (Object.isInvalid()) |
| 4850 | return SemaRef.ExprError(); |
| 4851 | |
| 4852 | // FIXME: Poor location information |
| 4853 | SourceLocation FakeLParenLoc |
| 4854 | = SemaRef.PP.getLocForEndOfToken( |
| 4855 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4856 | |
| 4857 | // Transform the call arguments. |
| 4858 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4859 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4860 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4861 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4862 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4863 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4864 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4865 | if (Arg.isInvalid()) |
| 4866 | return SemaRef.ExprError(); |
| 4867 | |
| 4868 | // FIXME: Poor source location information. |
| 4869 | SourceLocation FakeCommaLoc |
| 4870 | = SemaRef.PP.getLocForEndOfToken( |
| 4871 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4872 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4873 | Args.push_back(Arg.release()); |
| 4874 | } |
| 4875 | |
| 4876 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4877 | move_arg(Args), |
| 4878 | FakeCommaLocs.data(), |
| 4879 | E->getLocEnd()); |
| 4880 | } |
| 4881 | |
| 4882 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4883 | case OO_##Name: |
| 4884 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4885 | #include "clang/Basic/OperatorKinds.def" |
| 4886 | case OO_Subscript: |
| 4887 | // Handled below. |
| 4888 | break; |
| 4889 | |
| 4890 | case OO_Conditional: |
| 4891 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4892 | return SemaRef.ExprError(); |
| 4893 | |
| 4894 | case OO_None: |
| 4895 | case NUM_OVERLOADED_OPERATORS: |
| 4896 | llvm_unreachable("not an overloaded operator?"); |
| 4897 | return SemaRef.ExprError(); |
| 4898 | } |
| 4899 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4900 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4901 | if (Callee.isInvalid()) |
| 4902 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4903 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4904 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4905 | if (First.isInvalid()) |
| 4906 | return SemaRef.ExprError(); |
| 4907 | |
| 4908 | OwningExprResult Second(SemaRef); |
| 4909 | if (E->getNumArgs() == 2) { |
| 4910 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4911 | if (Second.isInvalid()) |
| 4912 | return SemaRef.ExprError(); |
| 4913 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4915 | if (!getDerived().AlwaysRebuild() && |
| 4916 | Callee.get() == E->getCallee() && |
| 4917 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4918 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4919 | return SemaRef.Owned(E->Retain()); |
| 4920 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4921 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4922 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4923 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4924 | move(First), |
| 4925 | move(Second)); |
| 4926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4928 | template<typename Derived> |
| 4929 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4930 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4931 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4932 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4934 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4936 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4937 | TypeSourceInfo *OldT; |
| 4938 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4939 | { |
| 4940 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4942 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4943 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4944 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4945 | OldT = E->getTypeInfoAsWritten(); |
| 4946 | NewT = getDerived().TransformType(OldT); |
| 4947 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | return SemaRef.ExprError(); |
| 4949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4951 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4952 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4953 | if (SubExpr.isInvalid()) |
| 4954 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4956 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4957 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4958 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4959 | return SemaRef.Owned(E->Retain()); |
| 4960 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4963 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4964 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4965 | SourceLocation FakeRParenLoc |
| 4966 | = SemaRef.PP.getLocForEndOfToken( |
| 4967 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4968 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4969 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4970 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4971 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4972 | FakeRAngleLoc, |
| 4973 | FakeRAngleLoc, |
| 4974 | move(SubExpr), |
| 4975 | FakeRParenLoc); |
| 4976 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4977 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4978 | template<typename Derived> |
| 4979 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4980 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4981 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4983 | |
| 4984 | template<typename Derived> |
| 4985 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4986 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4987 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4990 | template<typename Derived> |
| 4991 | Sema::OwningExprResult |
| 4992 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4993 | CXXReinterpretCastExpr *E) { |
| 4994 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4996 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4997 | template<typename Derived> |
| 4998 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4999 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5000 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5001 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5003 | template<typename Derived> |
| 5004 | Sema::OwningExprResult |
| 5005 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5006 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5007 | TypeSourceInfo *OldT; |
| 5008 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5009 | { |
| 5010 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5011 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5012 | OldT = E->getTypeInfoAsWritten(); |
| 5013 | NewT = getDerived().TransformType(OldT); |
| 5014 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5015 | return SemaRef.ExprError(); |
| 5016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5017 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5018 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5019 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5020 | if (SubExpr.isInvalid()) |
| 5021 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5023 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5024 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5025 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5026 | return SemaRef.Owned(E->Retain()); |
| 5027 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | // FIXME: The end of the type's source range is wrong |
| 5029 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5030 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5031 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5032 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5033 | move(SubExpr), |
| 5034 | E->getRParenLoc()); |
| 5035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5037 | template<typename Derived> |
| 5038 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5039 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5040 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5041 | TypeSourceInfo *TInfo |
| 5042 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5043 | if (!TInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5044 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5045 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5046 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5047 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5048 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5050 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5051 | E->getLocStart(), |
| 5052 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5053 | E->getLocEnd()); |
| 5054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | // We don't know whether the expression is potentially evaluated until |
| 5057 | // after we perform semantic analysis, so the expression is potentially |
| 5058 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5060 | Action::PotentiallyPotentiallyEvaluated); |
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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5063 | if (SubExpr.isInvalid()) |
| 5064 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5065 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5066 | if (!getDerived().AlwaysRebuild() && |
| 5067 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5068 | return SemaRef.Owned(E->Retain()); |
| 5069 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5070 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5071 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5072 | move(SubExpr), |
| 5073 | E->getLocEnd()); |
| 5074 | } |
| 5075 | |
| 5076 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5078 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5082 | template<typename Derived> |
| 5083 | Sema::OwningExprResult |
| 5084 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5085 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5086 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5087 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5089 | template<typename Derived> |
| 5090 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5091 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5092 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getType()); |
| 5095 | if (T.isNull()) |
| 5096 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5098 | if (!getDerived().AlwaysRebuild() && |
| 5099 | T == E->getType()) |
| 5100 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5101 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5102 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5103 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5104 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5105 | template<typename Derived> |
| 5106 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5107 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5108 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5109 | if (SubExpr.isInvalid()) |
| 5110 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5112 | if (!getDerived().AlwaysRebuild() && |
| 5113 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5114 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | |
| 5116 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5117 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5118 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5119 | template<typename Derived> |
| 5120 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5121 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5122 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5123 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5124 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5125 | if (!Param) |
| 5126 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5127 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5128 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5129 | Param == E->getParam()) |
| 5130 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5131 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5132 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5133 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5135 | template<typename Derived> |
| 5136 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5137 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5138 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5139 | |
| 5140 | QualType T = getDerived().TransformType(E->getType()); |
| 5141 | if (T.isNull()) |
| 5142 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | if (!getDerived().AlwaysRebuild() && |
| 5145 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5146 | return SemaRef.Owned(E->Retain()); |
| 5147 | |
| 5148 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5149 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5150 | T, |
| 5151 | E->getRParenLoc()); |
| 5152 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5154 | template<typename Derived> |
| 5155 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5156 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5157 | // Transform the type that we're allocating |
| 5158 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5159 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5160 | if (AllocType.isNull()) |
| 5161 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5163 | // Transform the size of the array we're allocating (if any). |
| 5164 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5165 | if (ArraySize.isInvalid()) |
| 5166 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | // Transform the placement arguments (if any). |
| 5169 | bool ArgumentChanged = false; |
| 5170 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5171 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5172 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5173 | if (Arg.isInvalid()) |
| 5174 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5177 | PlacementArgs.push_back(Arg.take()); |
| 5178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5180 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5181 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5182 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 5183 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5184 | if (Arg.isInvalid()) |
| 5185 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5187 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5188 | ConstructorArgs.push_back(Arg.take()); |
| 5189 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5191 | // Transform constructor, new operator, and delete operator. |
| 5192 | CXXConstructorDecl *Constructor = 0; |
| 5193 | if (E->getConstructor()) { |
| 5194 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5195 | getDerived().TransformDecl(E->getLocStart(), |
| 5196 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5197 | if (!Constructor) |
| 5198 | return SemaRef.ExprError(); |
| 5199 | } |
| 5200 | |
| 5201 | FunctionDecl *OperatorNew = 0; |
| 5202 | if (E->getOperatorNew()) { |
| 5203 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5204 | getDerived().TransformDecl(E->getLocStart(), |
| 5205 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5206 | if (!OperatorNew) |
| 5207 | return SemaRef.ExprError(); |
| 5208 | } |
| 5209 | |
| 5210 | FunctionDecl *OperatorDelete = 0; |
| 5211 | if (E->getOperatorDelete()) { |
| 5212 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5213 | getDerived().TransformDecl(E->getLocStart(), |
| 5214 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5215 | if (!OperatorDelete) |
| 5216 | return SemaRef.ExprError(); |
| 5217 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | if (!getDerived().AlwaysRebuild() && |
| 5220 | AllocType == E->getAllocatedType() && |
| 5221 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5222 | Constructor == E->getConstructor() && |
| 5223 | OperatorNew == E->getOperatorNew() && |
| 5224 | OperatorDelete == E->getOperatorDelete() && |
| 5225 | !ArgumentChanged) { |
| 5226 | // Mark any declarations we need as referenced. |
| 5227 | // FIXME: instantiation-specific. |
| 5228 | if (Constructor) |
| 5229 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5230 | if (OperatorNew) |
| 5231 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5232 | if (OperatorDelete) |
| 5233 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5235 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5237 | if (!ArraySize.get()) { |
| 5238 | // If no array size was specified, but the new expression was |
| 5239 | // instantiated with an array type (e.g., "new T" where T is |
| 5240 | // instantiated with "int[4]"), extract the outer bound from the |
| 5241 | // array type as our array size. We do this with constant and |
| 5242 | // dependently-sized array types. |
| 5243 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5244 | if (!ArrayT) { |
| 5245 | // Do nothing |
| 5246 | } else if (const ConstantArrayType *ConsArrayT |
| 5247 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5248 | ArraySize |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5249 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5250 | ConsArrayT->getSize(), |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5251 | SemaRef.Context.getSizeType(), |
| 5252 | /*FIXME:*/E->getLocStart())); |
| 5253 | AllocType = ConsArrayT->getElementType(); |
| 5254 | } else if (const DependentSizedArrayType *DepArrayT |
| 5255 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5256 | if (DepArrayT->getSizeExpr()) { |
| 5257 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5258 | AllocType = DepArrayT->getElementType(); |
| 5259 | } |
| 5260 | } |
| 5261 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5262 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5263 | E->isGlobalNew(), |
| 5264 | /*FIXME:*/E->getLocStart(), |
| 5265 | move_arg(PlacementArgs), |
| 5266 | /*FIXME:*/E->getLocStart(), |
| 5267 | E->isParenTypeId(), |
| 5268 | AllocType, |
| 5269 | /*FIXME:*/E->getLocStart(), |
| 5270 | /*FIXME:*/SourceRange(), |
| 5271 | move(ArraySize), |
| 5272 | /*FIXME:*/E->getLocStart(), |
| 5273 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5274 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5275 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5276 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5277 | template<typename Derived> |
| 5278 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5279 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5280 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5281 | if (Operand.isInvalid()) |
| 5282 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5283 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5284 | // Transform the delete operator, if known. |
| 5285 | FunctionDecl *OperatorDelete = 0; |
| 5286 | if (E->getOperatorDelete()) { |
| 5287 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5288 | getDerived().TransformDecl(E->getLocStart(), |
| 5289 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5290 | if (!OperatorDelete) |
| 5291 | return SemaRef.ExprError(); |
| 5292 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5293 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5294 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5295 | Operand.get() == E->getArgument() && |
| 5296 | OperatorDelete == E->getOperatorDelete()) { |
| 5297 | // Mark any declarations we need as referenced. |
| 5298 | // FIXME: instantiation-specific. |
| 5299 | if (OperatorDelete) |
| 5300 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5301 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5304 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5305 | E->isGlobalDelete(), |
| 5306 | E->isArrayForm(), |
| 5307 | move(Operand)); |
| 5308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5310 | template<typename Derived> |
| 5311 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5312 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5313 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5314 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5315 | if (Base.isInvalid()) |
| 5316 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5318 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5319 | bool MayBePseudoDestructor = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5320 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5321 | E->getOperatorLoc(), |
| 5322 | E->isArrow()? tok::arrow : tok::period, |
| 5323 | ObjectTypePtr, |
| 5324 | MayBePseudoDestructor); |
| 5325 | if (Base.isInvalid()) |
| 5326 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5327 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5328 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5329 | NestedNameSpecifier *Qualifier |
| 5330 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5331 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5332 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5333 | if (E->getQualifier() && !Qualifier) |
| 5334 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5336 | PseudoDestructorTypeStorage Destroyed; |
| 5337 | if (E->getDestroyedTypeInfo()) { |
| 5338 | TypeSourceInfo *DestroyedTypeInfo |
| 5339 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5340 | if (!DestroyedTypeInfo) |
| 5341 | return SemaRef.ExprError(); |
| 5342 | Destroyed = DestroyedTypeInfo; |
| 5343 | } else if (ObjectType->isDependentType()) { |
| 5344 | // We aren't likely to be able to resolve the identifier down to a type |
| 5345 | // now anyway, so just retain the identifier. |
| 5346 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5347 | E->getDestroyedTypeLoc()); |
| 5348 | } else { |
| 5349 | // Look for a destructor known with the given name. |
| 5350 | CXXScopeSpec SS; |
| 5351 | if (Qualifier) { |
| 5352 | SS.setScopeRep(Qualifier); |
| 5353 | SS.setRange(E->getQualifierRange()); |
| 5354 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5355 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5356 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5357 | *E->getDestroyedTypeIdentifier(), |
| 5358 | E->getDestroyedTypeLoc(), |
| 5359 | /*Scope=*/0, |
| 5360 | SS, ObjectTypePtr, |
| 5361 | false); |
| 5362 | if (!T) |
| 5363 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5364 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5365 | Destroyed |
| 5366 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5367 | E->getDestroyedTypeLoc()); |
| 5368 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5369 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5370 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5371 | if (E->getScopeTypeInfo()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5372 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5373 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5374 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5375 | return SemaRef.ExprError(); |
| 5376 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5377 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5378 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5379 | E->getOperatorLoc(), |
| 5380 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5381 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5382 | E->getQualifierRange(), |
| 5383 | ScopeTypeInfo, |
| 5384 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5385 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5386 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5388 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5389 | template<typename Derived> |
| 5390 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5391 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5392 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5393 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5394 | |
| 5395 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5396 | Sema::LookupOrdinaryName); |
| 5397 | |
| 5398 | // Transform all the decls. |
| 5399 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5400 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5401 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5402 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5403 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5404 | if (!InstD) { |
| 5405 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5406 | // This can happen because of dependent hiding. |
| 5407 | if (isa<UsingShadowDecl>(*I)) |
| 5408 | continue; |
| 5409 | else |
| 5410 | return SemaRef.ExprError(); |
| 5411 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5412 | |
| 5413 | // Expand using declarations. |
| 5414 | if (isa<UsingDecl>(InstD)) { |
| 5415 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5416 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5417 | E = UD->shadow_end(); I != E; ++I) |
| 5418 | R.addDecl(*I); |
| 5419 | continue; |
| 5420 | } |
| 5421 | |
| 5422 | R.addDecl(InstD); |
| 5423 | } |
| 5424 | |
| 5425 | // Resolve a kind, but don't do any further analysis. If it's |
| 5426 | // ambiguous, the callee needs to deal with it. |
| 5427 | R.resolveKind(); |
| 5428 | |
| 5429 | // Rebuild the nested-name qualifier, if present. |
| 5430 | CXXScopeSpec SS; |
| 5431 | NestedNameSpecifier *Qualifier = 0; |
| 5432 | if (Old->getQualifier()) { |
| 5433 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5434 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5435 | if (!Qualifier) |
| 5436 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5437 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5438 | SS.setScopeRep(Qualifier); |
| 5439 | SS.setRange(Old->getQualifierRange()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5442 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5443 | CXXRecordDecl *NamingClass |
| 5444 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5445 | Old->getNameLoc(), |
| 5446 | Old->getNamingClass())); |
| 5447 | if (!NamingClass) |
| 5448 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5449 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5450 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | // If we have no template arguments, it's a normal declaration name. |
| 5454 | if (!Old->hasExplicitTemplateArgs()) |
| 5455 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5456 | |
| 5457 | // If we have template arguments, rebuild them, then rebuild the |
| 5458 | // templateid expression. |
| 5459 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5460 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5461 | TemplateArgumentLoc Loc; |
| 5462 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5463 | return SemaRef.ExprError(); |
| 5464 | TransArgs.addArgument(Loc); |
| 5465 | } |
| 5466 | |
| 5467 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5468 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5469 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5471 | template<typename Derived> |
| 5472 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5473 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5474 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5477 | if (T.isNull()) |
| 5478 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 5481 | T == E->getQueriedType()) |
| 5482 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5483 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5484 | // FIXME: Bad location information |
| 5485 | SourceLocation FakeLParenLoc |
| 5486 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5487 | |
| 5488 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5489 | E->getLocStart(), |
| 5490 | /*FIXME:*/FakeLParenLoc, |
| 5491 | T, |
| 5492 | E->getLocEnd()); |
| 5493 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5494 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5495 | template<typename Derived> |
| 5496 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5498 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5499 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5500 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5501 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5502 | if (!NNS) |
| 5503 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5504 | |
| 5505 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5506 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 5507 | if (!Name) |
| 5508 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5509 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5510 | if (!E->hasExplicitTemplateArgs()) { |
| 5511 | if (!getDerived().AlwaysRebuild() && |
| 5512 | NNS == E->getQualifier() && |
| 5513 | Name == E->getDeclName()) |
| 5514 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5515 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5516 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5517 | E->getQualifierRange(), |
| 5518 | Name, E->getLocation(), |
| 5519 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5520 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5521 | |
| 5522 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5523 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5524 | TemplateArgumentLoc Loc; |
| 5525 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5526 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5527 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5528 | } |
| 5529 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5530 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5531 | E->getQualifierRange(), |
| 5532 | Name, E->getLocation(), |
| 5533 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | template<typename Derived> |
| 5537 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5538 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5539 | // CXXConstructExprs are always implicit, so when we have a |
| 5540 | // 1-argument construction we just transform that argument. |
| 5541 | if (E->getNumArgs() == 1 || |
| 5542 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5543 | return getDerived().TransformExpr(E->getArg(0)); |
| 5544 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5545 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5546 | |
| 5547 | QualType T = getDerived().TransformType(E->getType()); |
| 5548 | if (T.isNull()) |
| 5549 | return SemaRef.ExprError(); |
| 5550 | |
| 5551 | CXXConstructorDecl *Constructor |
| 5552 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5553 | getDerived().TransformDecl(E->getLocStart(), |
| 5554 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5555 | if (!Constructor) |
| 5556 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5557 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5558 | bool ArgumentChanged = false; |
| 5559 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5560 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5561 | ArgEnd = E->arg_end(); |
| 5562 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5563 | if (getDerived().DropCallArgument(*Arg)) { |
| 5564 | ArgumentChanged = true; |
| 5565 | break; |
| 5566 | } |
| 5567 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5569 | if (TransArg.isInvalid()) |
| 5570 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5571 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5572 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5573 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5574 | } |
| 5575 | |
| 5576 | if (!getDerived().AlwaysRebuild() && |
| 5577 | T == E->getType() && |
| 5578 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5579 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5580 | // Mark the constructor as referenced. |
| 5581 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5582 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5583 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5585 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5586 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5587 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5588 | move_arg(Args)); |
| 5589 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5590 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5591 | /// \brief Transform a C++ temporary-binding expression. |
| 5592 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5593 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5594 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | template<typename Derived> |
| 5596 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5597 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5598 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5599 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5600 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5601 | /// \brief Transform a C++ reference-binding expression. |
| 5602 | /// |
| 5603 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5604 | /// transform the subexpression and return that. |
| 5605 | template<typename Derived> |
| 5606 | Sema::OwningExprResult |
| 5607 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5608 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5609 | } |
| 5610 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5611 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5612 | /// be destroyed after the expression is evaluated. |
| 5613 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5614 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5615 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5616 | template<typename Derived> |
| 5617 | Sema::OwningExprResult |
| 5618 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5619 | CXXExprWithTemporaries *E) { |
| 5620 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5623 | template<typename Derived> |
| 5624 | Sema::OwningExprResult |
| 5625 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5626 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5627 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5628 | QualType T = getDerived().TransformType(E->getType()); |
| 5629 | if (T.isNull()) |
| 5630 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5632 | CXXConstructorDecl *Constructor |
| 5633 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5634 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5635 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5636 | if (!Constructor) |
| 5637 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5638 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5639 | bool ArgumentChanged = false; |
| 5640 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5641 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5642 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5643 | ArgEnd = E->arg_end(); |
| 5644 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5645 | if (getDerived().DropCallArgument(*Arg)) { |
| 5646 | ArgumentChanged = true; |
| 5647 | break; |
| 5648 | } |
| 5649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5650 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5651 | if (TransArg.isInvalid()) |
| 5652 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5655 | Args.push_back((Expr *)TransArg.release()); |
| 5656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5658 | if (!getDerived().AlwaysRebuild() && |
| 5659 | T == E->getType() && |
| 5660 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5661 | !ArgumentChanged) { |
| 5662 | // FIXME: Instantiation-specific |
| 5663 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5664 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5665 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5666 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5667 | // FIXME: Bogus location information |
| 5668 | SourceLocation CommaLoc; |
| 5669 | if (Args.size() > 1) { |
| 5670 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5672 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5673 | } |
| 5674 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5675 | T, |
| 5676 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5677 | move_arg(Args), |
| 5678 | &CommaLoc, |
| 5679 | E->getLocEnd()); |
| 5680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5681 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5682 | template<typename Derived> |
| 5683 | Sema::OwningExprResult |
| 5684 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5685 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5686 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5687 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5688 | if (T.isNull()) |
| 5689 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5690 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5691 | bool ArgumentChanged = false; |
| 5692 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5693 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5694 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5695 | ArgEnd = E->arg_end(); |
| 5696 | Arg != ArgEnd; ++Arg) { |
| 5697 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5698 | if (TransArg.isInvalid()) |
| 5699 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5700 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5701 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5702 | FakeCommaLocs.push_back( |
| 5703 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5704 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5706 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5707 | if (!getDerived().AlwaysRebuild() && |
| 5708 | T == E->getTypeAsWritten() && |
| 5709 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5710 | return SemaRef.Owned(E->Retain()); |
| 5711 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5712 | // FIXME: we're faking the locations of the commas |
| 5713 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5714 | T, |
| 5715 | E->getLParenLoc(), |
| 5716 | move_arg(Args), |
| 5717 | FakeCommaLocs.data(), |
| 5718 | E->getRParenLoc()); |
| 5719 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5720 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5721 | template<typename Derived> |
| 5722 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5723 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5724 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5725 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5726 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5727 | Expr *OldBase; |
| 5728 | QualType BaseType; |
| 5729 | QualType ObjectType; |
| 5730 | if (!E->isImplicitAccess()) { |
| 5731 | OldBase = E->getBase(); |
| 5732 | Base = getDerived().TransformExpr(OldBase); |
| 5733 | if (Base.isInvalid()) |
| 5734 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5735 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5736 | // Start the member reference and compute the object's type. |
| 5737 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5738 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5739 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5740 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5741 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5742 | ObjectTy, |
| 5743 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5744 | if (Base.isInvalid()) |
| 5745 | return SemaRef.ExprError(); |
| 5746 | |
| 5747 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5748 | BaseType = ((Expr*) Base.get())->getType(); |
| 5749 | } else { |
| 5750 | OldBase = 0; |
| 5751 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5752 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5755 | // Transform the first part of the nested-name-specifier that qualifies |
| 5756 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5757 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5758 | = getDerived().TransformFirstQualifierInScope( |
| 5759 | E->getFirstQualifierFoundInScope(), |
| 5760 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5761 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5762 | NestedNameSpecifier *Qualifier = 0; |
| 5763 | if (E->getQualifier()) { |
| 5764 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5765 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5766 | ObjectType, |
| 5767 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5768 | if (!Qualifier) |
| 5769 | return SemaRef.ExprError(); |
| 5770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5771 | |
| 5772 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5773 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5774 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5775 | if (!Name) |
| 5776 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5777 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5778 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5779 | // This is a reference to a member without an explicitly-specified |
| 5780 | // template argument list. Optimize for this common case. |
| 5781 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5782 | Base.get() == OldBase && |
| 5783 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5784 | Qualifier == E->getQualifier() && |
| 5785 | Name == E->getMember() && |
| 5786 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5787 | return SemaRef.Owned(E->Retain()); |
| 5788 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5789 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5790 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5791 | E->isArrow(), |
| 5792 | E->getOperatorLoc(), |
| 5793 | Qualifier, |
| 5794 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5795 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5796 | Name, |
| 5797 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5798 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5799 | } |
| 5800 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5801 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5802 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5803 | TemplateArgumentLoc Loc; |
| 5804 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5805 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5806 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5807 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5808 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5809 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5810 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5811 | E->isArrow(), |
| 5812 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5813 | Qualifier, |
| 5814 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5815 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5816 | Name, |
| 5817 | E->getMemberLoc(), |
| 5818 | &TransArgs); |
| 5819 | } |
| 5820 | |
| 5821 | template<typename Derived> |
| 5822 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5823 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5824 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5825 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5826 | QualType BaseType; |
| 5827 | if (!Old->isImplicitAccess()) { |
| 5828 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5829 | if (Base.isInvalid()) |
| 5830 | return SemaRef.ExprError(); |
| 5831 | BaseType = ((Expr*) Base.get())->getType(); |
| 5832 | } else { |
| 5833 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5834 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5835 | |
| 5836 | NestedNameSpecifier *Qualifier = 0; |
| 5837 | if (Old->getQualifier()) { |
| 5838 | Qualifier |
| 5839 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5840 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5841 | if (Qualifier == 0) |
| 5842 | return SemaRef.ExprError(); |
| 5843 | } |
| 5844 | |
| 5845 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5846 | Sema::LookupOrdinaryName); |
| 5847 | |
| 5848 | // Transform all the decls. |
| 5849 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5850 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5851 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5852 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5853 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5854 | if (!InstD) { |
| 5855 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5856 | // This can happen because of dependent hiding. |
| 5857 | if (isa<UsingShadowDecl>(*I)) |
| 5858 | continue; |
| 5859 | else |
| 5860 | return SemaRef.ExprError(); |
| 5861 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5862 | |
| 5863 | // Expand using declarations. |
| 5864 | if (isa<UsingDecl>(InstD)) { |
| 5865 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5866 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5867 | E = UD->shadow_end(); I != E; ++I) |
| 5868 | R.addDecl(*I); |
| 5869 | continue; |
| 5870 | } |
| 5871 | |
| 5872 | R.addDecl(InstD); |
| 5873 | } |
| 5874 | |
| 5875 | R.resolveKind(); |
| 5876 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5877 | // Determine the naming class. |
| 5878 | if (!Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5879 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5880 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5881 | Old->getMemberLoc(), |
| 5882 | Old->getNamingClass())); |
| 5883 | if (!NamingClass) |
| 5884 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5885 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5886 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5887 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5888 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5889 | TemplateArgumentListInfo TransArgs; |
| 5890 | if (Old->hasExplicitTemplateArgs()) { |
| 5891 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5892 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5893 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5894 | TemplateArgumentLoc Loc; |
| 5895 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5896 | Loc)) |
| 5897 | return SemaRef.ExprError(); |
| 5898 | TransArgs.addArgument(Loc); |
| 5899 | } |
| 5900 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5901 | |
| 5902 | // FIXME: to do this check properly, we will need to preserve the |
| 5903 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5904 | // base (and therefore couldn't do the check) and a |
| 5905 | // nested-name-qualifier (and therefore could do the lookup). |
| 5906 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5907 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5908 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5909 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5910 | Old->getOperatorLoc(), |
| 5911 | Old->isArrow(), |
| 5912 | Qualifier, |
| 5913 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5914 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5915 | R, |
| 5916 | (Old->hasExplicitTemplateArgs() |
| 5917 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | template<typename Derived> |
| 5921 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5922 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5923 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5926 | template<typename Derived> |
| 5927 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5928 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5929 | TypeSourceInfo *EncodedTypeInfo |
| 5930 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 5931 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5932 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5934 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5935 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5936 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5937 | |
| 5938 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 5939 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5940 | E->getRParenLoc()); |
| 5941 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5942 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5943 | template<typename Derived> |
| 5944 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5945 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5946 | // Transform arguments. |
| 5947 | bool ArgChanged = false; |
| 5948 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5949 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 5950 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 5951 | if (Arg.isInvalid()) |
| 5952 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5953 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5954 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 5955 | Args.push_back(Arg.takeAs<Expr>()); |
| 5956 | } |
| 5957 | |
| 5958 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 5959 | // Class message: transform the receiver type. |
| 5960 | TypeSourceInfo *ReceiverTypeInfo |
| 5961 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 5962 | if (!ReceiverTypeInfo) |
| 5963 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5964 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5965 | // If nothing changed, just retain the existing message send. |
| 5966 | if (!getDerived().AlwaysRebuild() && |
| 5967 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 5968 | return SemaRef.Owned(E->Retain()); |
| 5969 | |
| 5970 | // Build a new class message send. |
| 5971 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 5972 | E->getSelector(), |
| 5973 | E->getMethodDecl(), |
| 5974 | E->getLeftLoc(), |
| 5975 | move_arg(Args), |
| 5976 | E->getRightLoc()); |
| 5977 | } |
| 5978 | |
| 5979 | // Instance message: transform the receiver |
| 5980 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 5981 | "Only class and instance messages may be instantiated"); |
| 5982 | OwningExprResult Receiver |
| 5983 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 5984 | if (Receiver.isInvalid()) |
| 5985 | return SemaRef.ExprError(); |
| 5986 | |
| 5987 | // If nothing changed, just retain the existing message send. |
| 5988 | if (!getDerived().AlwaysRebuild() && |
| 5989 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 5990 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5991 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 5992 | // Build a new instance message send. |
| 5993 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 5994 | E->getSelector(), |
| 5995 | E->getMethodDecl(), |
| 5996 | E->getLeftLoc(), |
| 5997 | move_arg(Args), |
| 5998 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5999 | } |
| 6000 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6001 | template<typename Derived> |
| 6002 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6003 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6004 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6005 | } |
| 6006 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6007 | template<typename Derived> |
| 6008 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6009 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6010 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6011 | } |
| 6012 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6013 | template<typename Derived> |
| 6014 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6015 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6016 | // Transform the base expression. |
| 6017 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6018 | if (Base.isInvalid()) |
| 6019 | return SemaRef.ExprError(); |
| 6020 | |
| 6021 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6022 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6023 | // If nothing changed, just retain the existing expression. |
| 6024 | if (!getDerived().AlwaysRebuild() && |
| 6025 | Base.get() == E->getBase()) |
| 6026 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6027 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6028 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6029 | E->getLocation(), |
| 6030 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6033 | template<typename Derived> |
| 6034 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6035 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6036 | // Transform the base expression. |
| 6037 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6038 | if (Base.isInvalid()) |
| 6039 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6040 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6041 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6042 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6043 | // If nothing changed, just retain the existing expression. |
| 6044 | if (!getDerived().AlwaysRebuild() && |
| 6045 | Base.get() == E->getBase()) |
| 6046 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6047 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6048 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6049 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6050 | } |
| 6051 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6052 | template<typename Derived> |
| 6053 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6054 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6055 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6056 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6057 | // dependent parts. Just retain the existing declaration. |
| 6058 | if (E->getInterfaceDecl()) |
| 6059 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6060 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6061 | // Transform the base expression. |
| 6062 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6063 | if (Base.isInvalid()) |
| 6064 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6065 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6066 | // 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] | 6067 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6068 | // If nothing changed, just retain the existing expression. |
| 6069 | if (!getDerived().AlwaysRebuild() && |
| 6070 | Base.get() == E->getBase()) |
| 6071 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6072 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6073 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6074 | E->getGetterMethod(), |
| 6075 | E->getType(), |
| 6076 | E->getSetterMethod(), |
| 6077 | E->getLocation(), |
| 6078 | move(Base)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6079 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6082 | template<typename Derived> |
| 6083 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6084 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6085 | // Can never occur in a dependent context. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6086 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6089 | template<typename Derived> |
| 6090 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6091 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6092 | // Transform the base expression. |
| 6093 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6094 | if (Base.isInvalid()) |
| 6095 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6096 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6097 | // If nothing changed, just retain the existing expression. |
| 6098 | if (!getDerived().AlwaysRebuild() && |
| 6099 | Base.get() == E->getBase()) |
| 6100 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6101 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6102 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6103 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6104 | } |
| 6105 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6106 | template<typename Derived> |
| 6107 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6108 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6109 | bool ArgumentChanged = false; |
| 6110 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6111 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6112 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6113 | if (SubExpr.isInvalid()) |
| 6114 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6117 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6118 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6120 | if (!getDerived().AlwaysRebuild() && |
| 6121 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6122 | return SemaRef.Owned(E->Retain()); |
| 6123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6124 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6125 | move_arg(SubExprs), |
| 6126 | E->getRParenLoc()); |
| 6127 | } |
| 6128 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6129 | template<typename Derived> |
| 6130 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6131 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6132 | // FIXME: Implement this! |
| 6133 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6134 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6135 | } |
| 6136 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6137 | template<typename Derived> |
| 6138 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6139 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6140 | // FIXME: Implement this! |
| 6141 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6142 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6143 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6144 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6145 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6146 | // Type reconstruction |
| 6147 | //===----------------------------------------------------------------------===// |
| 6148 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6149 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6150 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6151 | SourceLocation Star) { |
| 6152 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6153 | getDerived().getBaseEntity()); |
| 6154 | } |
| 6155 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6156 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6157 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6158 | SourceLocation Star) { |
| 6159 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6160 | getDerived().getBaseEntity()); |
| 6161 | } |
| 6162 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6163 | template<typename Derived> |
| 6164 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6165 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6166 | bool WrittenAsLValue, |
| 6167 | SourceLocation Sigil) { |
| 6168 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 6169 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6173 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6174 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6175 | QualType ClassType, |
| 6176 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 6177 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6178 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6182 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6183 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6184 | ArrayType::ArraySizeModifier SizeMod, |
| 6185 | const llvm::APInt *Size, |
| 6186 | Expr *SizeExpr, |
| 6187 | unsigned IndexTypeQuals, |
| 6188 | SourceRange BracketsRange) { |
| 6189 | if (SizeExpr || !Size) |
| 6190 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6191 | IndexTypeQuals, BracketsRange, |
| 6192 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6193 | |
| 6194 | QualType Types[] = { |
| 6195 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6196 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6197 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6198 | }; |
| 6199 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6200 | QualType SizeType; |
| 6201 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6202 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6203 | SizeType = Types[I]; |
| 6204 | break; |
| 6205 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6206 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6207 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6208 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6209 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6210 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6211 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6212 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6213 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6214 | QualType |
| 6215 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6216 | ArrayType::ArraySizeModifier SizeMod, |
| 6217 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6218 | unsigned IndexTypeQuals, |
| 6219 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6220 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6221 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6225 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6226 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6227 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6228 | unsigned IndexTypeQuals, |
| 6229 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6230 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6231 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6232 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6233 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6234 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6235 | QualType |
| 6236 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6237 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6238 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6239 | unsigned IndexTypeQuals, |
| 6240 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6241 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6242 | SizeExpr.takeAs<Expr>(), |
| 6243 | IndexTypeQuals, BracketsRange); |
| 6244 | } |
| 6245 | |
| 6246 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6247 | QualType |
| 6248 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6249 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6250 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6251 | unsigned IndexTypeQuals, |
| 6252 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6253 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6254 | SizeExpr.takeAs<Expr>(), |
| 6255 | IndexTypeQuals, BracketsRange); |
| 6256 | } |
| 6257 | |
| 6258 | template<typename Derived> |
| 6259 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6260 | unsigned NumElements, |
| 6261 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6262 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 6263 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 6264 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6265 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6266 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6267 | template<typename Derived> |
| 6268 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6269 | unsigned NumElements, |
| 6270 | SourceLocation AttributeLoc) { |
| 6271 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6272 | NumElements, true); |
| 6273 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6274 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6275 | AttributeLoc); |
| 6276 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6277 | AttributeLoc); |
| 6278 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6279 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6280 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6281 | QualType |
| 6282 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6283 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6284 | SourceLocation AttributeLoc) { |
| 6285 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6287 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6288 | template<typename Derived> |
| 6289 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6290 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6291 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6292 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6293 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6294 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6295 | Quals, |
| 6296 | getDerived().getBaseLocation(), |
| 6297 | getDerived().getBaseEntity()); |
| 6298 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6299 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6300 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6301 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6302 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6303 | } |
| 6304 | |
| 6305 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6306 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6307 | assert(D && "no decl found"); |
| 6308 | if (D->isInvalidDecl()) return QualType(); |
| 6309 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6310 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6311 | TypeDecl *Ty; |
| 6312 | if (isa<UsingDecl>(D)) { |
| 6313 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6314 | assert(Using->isTypeName() && |
| 6315 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6316 | |
| 6317 | // A valid resolved using typename decl points to exactly one type decl. |
| 6318 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6319 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6320 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6321 | } else { |
| 6322 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6323 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6324 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6325 | } |
| 6326 | |
| 6327 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6328 | } |
| 6329 | |
| 6330 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6331 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6332 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6333 | } |
| 6334 | |
| 6335 | template<typename Derived> |
| 6336 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6337 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6338 | } |
| 6339 | |
| 6340 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6341 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6342 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6343 | } |
| 6344 | |
| 6345 | template<typename Derived> |
| 6346 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6347 | TemplateName Template, |
| 6348 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6349 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6350 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6352 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6353 | template<typename Derived> |
| 6354 | NestedNameSpecifier * |
| 6355 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6356 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6357 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6358 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6359 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6360 | CXXScopeSpec SS; |
| 6361 | // FIXME: The source location information is all wrong. |
| 6362 | SS.setRange(Range); |
| 6363 | SS.setScopeRep(Prefix); |
| 6364 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6365 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6366 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6367 | ObjectType, |
| 6368 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6369 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | template<typename Derived> |
| 6373 | NestedNameSpecifier * |
| 6374 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6375 | SourceRange Range, |
| 6376 | NamespaceDecl *NS) { |
| 6377 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6378 | } |
| 6379 | |
| 6380 | template<typename Derived> |
| 6381 | NestedNameSpecifier * |
| 6382 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6383 | SourceRange Range, |
| 6384 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6385 | QualType T) { |
| 6386 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6387 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6388 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6389 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6390 | T.getTypePtr()); |
| 6391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6392 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6393 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6394 | return 0; |
| 6395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6396 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6397 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6398 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6399 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6400 | bool TemplateKW, |
| 6401 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6402 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6403 | Template); |
| 6404 | } |
| 6405 | |
| 6406 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6407 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6408 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6409 | const IdentifierInfo &II, |
| 6410 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6411 | CXXScopeSpec SS; |
| 6412 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6413 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6414 | UnqualifiedId Name; |
| 6415 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6416 | return getSema().ActOnDependentTemplateName( |
| 6417 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6418 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6419 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6420 | ObjectType.getAsOpaquePtr(), |
| 6421 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6422 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6425 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6426 | TemplateName |
| 6427 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6428 | OverloadedOperatorKind Operator, |
| 6429 | QualType ObjectType) { |
| 6430 | CXXScopeSpec SS; |
| 6431 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6432 | SS.setScopeRep(Qualifier); |
| 6433 | UnqualifiedId Name; |
| 6434 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6435 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6436 | Operator, SymbolLocations); |
| 6437 | return getSema().ActOnDependentTemplateName( |
| 6438 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6439 | SS, |
| 6440 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 6441 | ObjectType.getAsOpaquePtr(), |
| 6442 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6443 | .template getAsVal<TemplateName>(); |
| 6444 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6445 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6446 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6447 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6448 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6449 | SourceLocation OpLoc, |
| 6450 | ExprArg Callee, |
| 6451 | ExprArg First, |
| 6452 | ExprArg Second) { |
| 6453 | Expr *FirstExpr = (Expr *)First.get(); |
| 6454 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6455 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6456 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6458 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6459 | if (Op == OO_Subscript) { |
| 6460 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6461 | !SecondExpr->getType()->isOverloadableType()) |
| 6462 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6463 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6464 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6465 | } else if (Op == OO_Arrow) { |
| 6466 | // -> is never a builtin operation. |
| 6467 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6468 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6469 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6470 | // The argument is not of overloadable type, so try to create a |
| 6471 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6472 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6473 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6474 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6475 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6476 | } |
| 6477 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6478 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6479 | !SecondExpr->getType()->isOverloadableType()) { |
| 6480 | // Neither of the arguments is an overloadable type, so try to |
| 6481 | // create a built-in binary operation. |
| 6482 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6483 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6484 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6485 | if (Result.isInvalid()) |
| 6486 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6487 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6488 | First.release(); |
| 6489 | Second.release(); |
| 6490 | return move(Result); |
| 6491 | } |
| 6492 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6493 | |
| 6494 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6495 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6496 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6497 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6498 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6499 | assert(ULE->requiresADL()); |
| 6500 | |
| 6501 | // FIXME: Do we have to check |
| 6502 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6503 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6504 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6505 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6506 | } |
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 | // Add any functions found via argument-dependent lookup. |
| 6509 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6510 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6512 | // Create the overloaded operator invocation for unary operators. |
| 6513 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6515 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6516 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6517 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6518 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6519 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6520 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6521 | OpLoc, |
| 6522 | move(First), |
| 6523 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6524 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6525 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6526 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6527 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6528 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6529 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6530 | if (Result.isInvalid()) |
| 6531 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6533 | First.release(); |
| 6534 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6535 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6537 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6538 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6539 | Sema::OwningExprResult |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6540 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6541 | SourceLocation OperatorLoc, |
| 6542 | bool isArrow, |
| 6543 | NestedNameSpecifier *Qualifier, |
| 6544 | SourceRange QualifierRange, |
| 6545 | TypeSourceInfo *ScopeType, |
| 6546 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6547 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6548 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6549 | CXXScopeSpec SS; |
| 6550 | if (Qualifier) { |
| 6551 | SS.setRange(QualifierRange); |
| 6552 | SS.setScopeRep(Qualifier); |
| 6553 | } |
| 6554 | |
| 6555 | Expr *BaseE = (Expr *)Base.get(); |
| 6556 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6557 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6558 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6559 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6560 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6561 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6562 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6563 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6564 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6565 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6566 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6567 | /*FIXME?*/true); |
| 6568 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6569 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6570 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6571 | DeclarationName Name |
| 6572 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6573 | SemaRef.Context.getCanonicalType(DestroyedType->getType())); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6574 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6575 | // FIXME: the ScopeType should be tacked onto SS. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6576 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6577 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6578 | OperatorLoc, isArrow, |
| 6579 | SS, /*FIXME: FirstQualifier*/ 0, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6580 | Name, Destroyed.getLocation(), |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6581 | /*TemplateArgs*/ 0); |
| 6582 | } |
| 6583 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6584 | } // end namespace clang |
| 6585 | |
| 6586 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |