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 | |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 16 | #include "clang/Sema/Sema.h" |
| 17 | #include "clang/Sema/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" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Ownership.h" |
| 28 | #include "clang/Sema/Designator.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 98 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 99 | /// \brief Initializes a new tree transformer. |
| 100 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 102 | /// \brief Retrieves a reference to the derived class. |
| 103 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 104 | |
| 105 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | const Derived &getDerived() const { |
| 107 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 111 | /// this tree transform. |
| 112 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 114 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 115 | /// if none of the children have changed. |
| 116 | /// |
| 117 | /// Subclasses may override this function to specify when the transformation |
| 118 | /// should rebuild all AST nodes. |
| 119 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 121 | /// \brief Returns the location of the entity being transformed, if that |
| 122 | /// information was not available elsewhere in the AST. |
| 123 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 125 | /// provide an alternative implementation that provides better location |
| 126 | /// information. |
| 127 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 129 | /// \brief Returns the name of the entity being transformed, if that |
| 130 | /// information was not available elsewhere in the AST. |
| 131 | /// |
| 132 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 133 | /// implementation with a more precise name. |
| 134 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 136 | /// \brief Sets the "base" location and entity when that |
| 137 | /// information is known based on another transformation. |
| 138 | /// |
| 139 | /// By default, the source location and entity are ignored. Subclasses can |
| 140 | /// override this function to provide a customized implementation. |
| 141 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 143 | /// \brief RAII object that temporarily sets the base location and entity |
| 144 | /// used for reporting diagnostics in types. |
| 145 | class TemporaryBase { |
| 146 | TreeTransform &Self; |
| 147 | SourceLocation OldLocation; |
| 148 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 150 | public: |
| 151 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 152 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 153 | OldLocation = Self.getDerived().getBaseLocation(); |
| 154 | OldEntity = Self.getDerived().getBaseEntity(); |
| 155 | Self.getDerived().setBase(Location, Entity); |
| 156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 158 | ~TemporaryBase() { |
| 159 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 160 | } |
| 161 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
| 163 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 164 | /// transformed. |
| 165 | /// |
| 166 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | /// 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] | 168 | /// not change. For example, template instantiation need not traverse |
| 169 | /// non-dependent types. |
| 170 | bool AlreadyTransformed(QualType T) { |
| 171 | return T.isNull(); |
| 172 | } |
| 173 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 174 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 175 | /// because it is a default argument. |
| 176 | /// |
| 177 | /// Subclasses can provide an alternative implementation of this routine to |
| 178 | /// determine which kinds of call arguments get dropped. By default, |
| 179 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 180 | bool DropCallArgument(Expr *E) { |
| 181 | return E->isDefaultArgument(); |
| 182 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 183 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 184 | /// \brief Transforms the given type into another type. |
| 185 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 186 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 187 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 188 | /// function. This is expensive, but we don't mind, because |
| 189 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 190 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 191 | /// |
| 192 | /// \returns the transformed type. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 193 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 195 | /// \brief Transforms the given type-with-location into a new |
| 196 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 197 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 198 | /// By default, this routine transforms a type by delegating to the |
| 199 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 200 | /// may override this function (to take over all type |
| 201 | /// transformations) or some set of the TransformXXXType functions |
| 202 | /// to alter the transformation. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 203 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 204 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 205 | |
| 206 | /// \brief Transform the given type-with-location into a new |
| 207 | /// type, collecting location information in the given builder |
| 208 | /// as necessary. |
| 209 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 210 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 211 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 213 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 214 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 216 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 217 | /// statement or the TransformExpr() function to transform an expression. |
| 218 | /// Subclasses may override this function to transform statements using some |
| 219 | /// other mechanism. |
| 220 | /// |
| 221 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 222 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 223 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 224 | /// \brief Transform the given expression. |
| 225 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 226 | /// By default, this routine transforms an expression by delegating to the |
| 227 | /// appropriate TransformXXXExpr function to build a new expression. |
| 228 | /// Subclasses may override this function to transform expressions using some |
| 229 | /// other mechanism. |
| 230 | /// |
| 231 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 232 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 233 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 234 | /// \brief Transform the given declaration, which is referenced from a type |
| 235 | /// or expression. |
| 236 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 237 | /// By default, acts as the identity function on declarations. Subclasses |
| 238 | /// may override this function to provide alternate behavior. |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 239 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 240 | |
| 241 | /// \brief Transform the definition of the given declaration. |
| 242 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 243 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 244 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 245 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 246 | return getDerived().TransformDecl(Loc, D); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 247 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 249 | /// \brief Transform the given declaration, which was the first part of a |
| 250 | /// nested-name-specifier in a member access expression. |
| 251 | /// |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 252 | /// This specific declaration transformation only applies to the first |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 253 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 254 | /// the \c T in \c x->T::member |
| 255 | /// |
| 256 | /// By default, invokes TransformDecl() to transform the declaration. |
| 257 | /// Subclasses may override this function to provide alternate behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 258 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 259 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 260 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 261 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 262 | /// \brief Transform the given nested-name-specifier. |
| 263 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 265 | /// nested-name-specifier. Subclasses may override this function to provide |
| 266 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 267 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 268 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 269 | QualType ObjectType = QualType(), |
| 270 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 271 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 272 | /// \brief Transform the given declaration name. |
| 273 | /// |
| 274 | /// By default, transforms the types of conversion function, constructor, |
| 275 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 276 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 277 | /// override this function to provide alternate behavior. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 278 | DeclarationNameInfo |
| 279 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 280 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 282 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 283 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 284 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 286 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 287 | TemplateName TransformTemplateName(TemplateName Name, |
| 288 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 290 | /// \brief Transform the given template argument. |
| 291 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | /// By default, this operation transforms the type, expression, or |
| 293 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 294 | /// new template argument from the transformed result. Subclasses may |
| 295 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 296 | /// |
| 297 | /// Returns true if there was an error. |
| 298 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 299 | TemplateArgumentLoc &Output); |
| 300 | |
| 301 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 302 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 303 | TemplateArgumentLoc &ArgLoc); |
| 304 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 305 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 306 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 307 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 308 | getDerived().getBaseLocation()); |
| 309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 311 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 312 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 313 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 314 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 315 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 316 | |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 317 | /// \brief Transforms the parameters of a function type into the |
| 318 | /// given vectors. |
| 319 | /// |
| 320 | /// The result vectors should be kept in sync; null entries in the |
| 321 | /// variables vector are acceptable. |
| 322 | /// |
| 323 | /// Return true on error. |
| 324 | bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 325 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 326 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars); |
| 327 | |
| 328 | /// \brief Transforms a single function-type parameter. Return null |
| 329 | /// on error. |
| 330 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); |
| 331 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 332 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 333 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 334 | |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 335 | QualType |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 336 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 337 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 338 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 339 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Zhongxing Xu | 105dfb5 | 2010-04-21 06:32:25 +0000 | [diff] [blame] | 340 | OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 342 | #define STMT(Node, Parent) \ |
| 343 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 344 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 345 | OwningExprResult Transform##Node(Node *E); |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 346 | #define ABSTRACT_STMT(Stmt) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 347 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 349 | /// \brief Build a new pointer type given its pointee type. |
| 350 | /// |
| 351 | /// By default, performs semantic analysis when building the pointer type. |
| 352 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 353 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 354 | |
| 355 | /// \brief Build a new block pointer type given its pointee type. |
| 356 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 358 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 359 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 360 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 361 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 362 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 363 | /// By default, performs semantic analysis when building the |
| 364 | /// reference type. Subclasses may override this routine to provide |
| 365 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 366 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 367 | /// \param LValue whether the type was written with an lvalue sigil |
| 368 | /// or an rvalue sigil. |
| 369 | QualType RebuildReferenceType(QualType ReferentType, |
| 370 | bool LValue, |
| 371 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 373 | /// \brief Build a new member pointer type given the pointee type and the |
| 374 | /// class type it refers into. |
| 375 | /// |
| 376 | /// By default, performs semantic analysis when building the member pointer |
| 377 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 378 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 379 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 381 | /// \brief Build a new array type given the element type, size |
| 382 | /// modifier, size of the array (if known), size expression, and index type |
| 383 | /// qualifiers. |
| 384 | /// |
| 385 | /// By default, performs semantic analysis when building the array type. |
| 386 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 388 | QualType RebuildArrayType(QualType ElementType, |
| 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt *Size, |
| 391 | Expr *SizeExpr, |
| 392 | unsigned IndexTypeQuals, |
| 393 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 395 | /// \brief Build a new constant array type given the element type, size |
| 396 | /// modifier, (known) size of the array, and index type qualifiers. |
| 397 | /// |
| 398 | /// By default, performs semantic analysis when building the array type. |
| 399 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 401 | ArrayType::ArraySizeModifier SizeMod, |
| 402 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 403 | unsigned IndexTypeQuals, |
| 404 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | /// \brief Build a new incomplete array type given the element type, size |
| 407 | /// modifier, and index type qualifiers. |
| 408 | /// |
| 409 | /// By default, performs semantic analysis when building the array type. |
| 410 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 413 | unsigned IndexTypeQuals, |
| 414 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 415 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 417 | /// size modifier, size expression, and index type qualifiers. |
| 418 | /// |
| 419 | /// By default, performs semantic analysis when building the array type. |
| 420 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 422 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 423 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 424 | unsigned IndexTypeQuals, |
| 425 | SourceRange BracketsRange); |
| 426 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 428 | /// size modifier, size expression, and index type qualifiers. |
| 429 | /// |
| 430 | /// By default, performs semantic analysis when building the array type. |
| 431 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 434 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 435 | unsigned IndexTypeQuals, |
| 436 | SourceRange BracketsRange); |
| 437 | |
| 438 | /// \brief Build a new vector type given the element type and |
| 439 | /// number of elements. |
| 440 | /// |
| 441 | /// By default, performs semantic analysis when building the vector type. |
| 442 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 443 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 444 | VectorType::AltiVecSpecific AltiVecSpec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 445 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 446 | /// \brief Build a new extended vector type given the element type and |
| 447 | /// number of elements. |
| 448 | /// |
| 449 | /// By default, performs semantic analysis when building the vector type. |
| 450 | /// Subclasses may override this routine to provide different behavior. |
| 451 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 452 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 453 | |
| 454 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 455 | /// given the element type and number of elements. |
| 456 | /// |
| 457 | /// By default, performs semantic analysis when building the vector type. |
| 458 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 459 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 460 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 461 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 462 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 463 | /// \brief Build a new function type. |
| 464 | /// |
| 465 | /// By default, performs semantic analysis when building the function type. |
| 466 | /// Subclasses may override this routine to provide different behavior. |
| 467 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 468 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 469 | unsigned NumParamTypes, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 470 | bool Variadic, unsigned Quals, |
| 471 | const FunctionType::ExtInfo &Info); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 472 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 473 | /// \brief Build a new unprototyped function type. |
| 474 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 475 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 476 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 477 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 478 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 479 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 480 | /// \brief Build a new typedef type. |
| 481 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 482 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 483 | } |
| 484 | |
| 485 | /// \brief Build a new class/struct/union type. |
| 486 | QualType RebuildRecordType(RecordDecl *Record) { |
| 487 | return SemaRef.Context.getTypeDeclType(Record); |
| 488 | } |
| 489 | |
| 490 | /// \brief Build a new Enum type. |
| 491 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 492 | return SemaRef.Context.getTypeDeclType(Enum); |
| 493 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 494 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 496 | /// |
| 497 | /// By default, performs semantic analysis when building the typeof type. |
| 498 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 499 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 500 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 502 | /// |
| 503 | /// By default, builds a new TypeOfType with the given underlying type. |
| 504 | QualType RebuildTypeOfType(QualType Underlying); |
| 505 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 507 | /// |
| 508 | /// By default, performs semantic analysis when building the decltype type. |
| 509 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 510 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// \brief Build a new template specialization type. |
| 513 | /// |
| 514 | /// By default, performs semantic analysis when building the template |
| 515 | /// specialization type. Subclasses may override this routine to provide |
| 516 | /// different behavior. |
| 517 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 518 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 519 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | /// \brief Build a new qualified name type. |
| 522 | /// |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 523 | /// By default, builds a new ElaboratedType type from the keyword, |
| 524 | /// the nested-name-specifier and the named type. |
| 525 | /// Subclasses may override this routine to provide different behavior. |
| 526 | QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword, |
| 527 | NestedNameSpecifier *NNS, QualType Named) { |
| 528 | return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | |
| 531 | /// \brief Build a new typename type that refers to a template-id. |
| 532 | /// |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 533 | /// By default, builds a new DependentNameType type from the |
| 534 | /// nested-name-specifier and the given type. Subclasses may override |
| 535 | /// this routine to provide different behavior. |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 536 | QualType RebuildDependentTemplateSpecializationType( |
| 537 | ElaboratedTypeKeyword Keyword, |
| 538 | NestedNameSpecifier *NNS, |
| 539 | const IdentifierInfo *Name, |
| 540 | SourceLocation NameLoc, |
| 541 | const TemplateArgumentListInfo &Args) { |
| 542 | // Rebuild the template name. |
| 543 | // TODO: avoid TemplateName abstraction |
| 544 | TemplateName InstName = |
| 545 | getDerived().RebuildTemplateName(NNS, *Name, QualType()); |
| 546 | |
Douglas Gregor | 7ba0c3f | 2010-06-18 22:12:56 +0000 | [diff] [blame] | 547 | if (InstName.isNull()) |
| 548 | return QualType(); |
| 549 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 550 | // If it's still dependent, make a dependent specialization. |
| 551 | if (InstName.getAsDependentTemplateName()) |
| 552 | return SemaRef.Context.getDependentTemplateSpecializationType( |
| 553 | Keyword, NNS, Name, Args); |
| 554 | |
| 555 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 556 | // specialization. |
| 557 | QualType T = |
| 558 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 559 | if (T.isNull()) return QualType(); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 560 | |
Abramo Bagnara | f9985b4 | 2010-08-10 13:46:45 +0000 | [diff] [blame] | 561 | // NOTE: NNS is already recorded in template specialization type T. |
| 562 | return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 564 | |
| 565 | /// \brief Build a new typename type that refers to an identifier. |
| 566 | /// |
| 567 | /// By default, performs semantic analysis when building the typename type |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 568 | /// (or elaborated type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 569 | /// different behavior. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 570 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
Douglas Gregor | 0208535 | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 571 | NestedNameSpecifier *NNS, |
| 572 | const IdentifierInfo *Id, |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 573 | SourceLocation KeywordLoc, |
| 574 | SourceRange NNSRange, |
| 575 | SourceLocation IdLoc) { |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 576 | CXXScopeSpec SS; |
| 577 | SS.setScopeRep(NNS); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 578 | SS.setRange(NNSRange); |
| 579 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 580 | if (NNS->isDependent()) { |
| 581 | // If the name is still dependent, just build a new dependent name type. |
| 582 | if (!SemaRef.computeDeclContext(SS)) |
| 583 | return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); |
| 584 | } |
| 585 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 586 | if (Keyword == ETK_None || Keyword == ETK_Typename) |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 587 | return SemaRef.CheckTypenameType(Keyword, NNS, *Id, |
| 588 | KeywordLoc, NNSRange, IdLoc); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 589 | |
| 590 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 591 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 592 | // We had a dependent elaborated-type-specifier that has been transformed |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 593 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 594 | // referring to. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 595 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 596 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 597 | if (!DC) |
| 598 | return QualType(); |
| 599 | |
John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 600 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 601 | return QualType(); |
| 602 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 603 | TagDecl *Tag = 0; |
| 604 | SemaRef.LookupQualifiedName(Result, DC); |
| 605 | switch (Result.getResultKind()) { |
| 606 | case LookupResult::NotFound: |
| 607 | case LookupResult::NotFoundInCurrentInstantiation: |
| 608 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 610 | case LookupResult::Found: |
| 611 | Tag = Result.getAsSingle<TagDecl>(); |
| 612 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 614 | case LookupResult::FoundOverloaded: |
| 615 | case LookupResult::FoundUnresolvedValue: |
| 616 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| 617 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 618 | |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 619 | case LookupResult::Ambiguous: |
| 620 | // Let the LookupResult structure handle ambiguities. |
| 621 | return QualType(); |
| 622 | } |
| 623 | |
| 624 | if (!Tag) { |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 625 | // FIXME: Would be nice to highlight just the source range. |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 626 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
Douglas Gregor | f5af358 | 2010-03-31 23:17:41 +0000 | [diff] [blame] | 627 | << Kind << Id << DC; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 628 | return QualType(); |
| 629 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 630 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 631 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { |
| 632 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 633 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 634 | return QualType(); |
| 635 | } |
| 636 | |
| 637 | // Build the elaborated-type-specifier type. |
| 638 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 639 | return SemaRef.Context.getElaboratedType(Keyword, NNS, T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 640 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 642 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 643 | /// identifier that names the next step in the nested-name-specifier. |
| 644 | /// |
| 645 | /// By default, performs semantic analysis when building the new |
| 646 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 647 | /// different behavior. |
| 648 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 649 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 650 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 651 | QualType ObjectType, |
| 652 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 653 | |
| 654 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 655 | /// namespace named in the next step in the nested-name-specifier. |
| 656 | /// |
| 657 | /// By default, performs semantic analysis when building the new |
| 658 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 659 | /// different behavior. |
| 660 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 661 | SourceRange Range, |
| 662 | NamespaceDecl *NS); |
| 663 | |
| 664 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 665 | /// type named in the next step in the nested-name-specifier. |
| 666 | /// |
| 667 | /// By default, performs semantic analysis when building the new |
| 668 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 669 | /// different behavior. |
| 670 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 671 | SourceRange Range, |
| 672 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 673 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 674 | |
| 675 | /// \brief Build a new template name given a nested name specifier, a flag |
| 676 | /// indicating whether the "template" keyword was provided, and the template |
| 677 | /// that the template name refers to. |
| 678 | /// |
| 679 | /// By default, builds the new template name directly. Subclasses may override |
| 680 | /// this routine to provide different behavior. |
| 681 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 682 | bool TemplateKW, |
| 683 | TemplateDecl *Template); |
| 684 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 685 | /// \brief Build a new template name given a nested name specifier and the |
| 686 | /// name that is referred to as a template. |
| 687 | /// |
| 688 | /// By default, performs semantic analysis to determine whether the name can |
| 689 | /// be resolved to a specific template, then builds the appropriate kind of |
| 690 | /// template name. Subclasses may override this routine to provide different |
| 691 | /// behavior. |
| 692 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 693 | const IdentifierInfo &II, |
| 694 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 696 | /// \brief Build a new template name given a nested name specifier and the |
| 697 | /// overloaded operator name that is referred to as a template. |
| 698 | /// |
| 699 | /// By default, performs semantic analysis to determine whether the name can |
| 700 | /// be resolved to a specific template, then builds the appropriate kind of |
| 701 | /// template name. Subclasses may override this routine to provide different |
| 702 | /// behavior. |
| 703 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 704 | OverloadedOperatorKind Operator, |
| 705 | QualType ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 706 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 707 | /// \brief Build a new compound statement. |
| 708 | /// |
| 709 | /// By default, performs semantic analysis to build the new statement. |
| 710 | /// Subclasses may override this routine to provide different behavior. |
| 711 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 712 | MultiStmtArg Statements, |
| 713 | SourceLocation RBraceLoc, |
| 714 | bool IsStmtExpr) { |
| 715 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 716 | IsStmtExpr); |
| 717 | } |
| 718 | |
| 719 | /// \brief Build a new case statement. |
| 720 | /// |
| 721 | /// By default, performs semantic analysis to build the new statement. |
| 722 | /// Subclasses may override this routine to provide different behavior. |
| 723 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 724 | ExprArg LHS, |
| 725 | SourceLocation EllipsisLoc, |
| 726 | ExprArg RHS, |
| 727 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 729 | ColonLoc); |
| 730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 732 | /// \brief Attach the body to a new case statement. |
| 733 | /// |
| 734 | /// By default, performs semantic analysis to build the new statement. |
| 735 | /// Subclasses may override this routine to provide different behavior. |
| 736 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 737 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 738 | return move(S); |
| 739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 741 | /// \brief Build a new default statement. |
| 742 | /// |
| 743 | /// By default, performs semantic analysis to build the new statement. |
| 744 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 746 | SourceLocation ColonLoc, |
| 747 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 749 | /*CurScope=*/0); |
| 750 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | /// \brief Build a new label statement. |
| 753 | /// |
| 754 | /// By default, performs semantic analysis to build the new statement. |
| 755 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 757 | IdentifierInfo *Id, |
| 758 | SourceLocation ColonLoc, |
| 759 | StmtArg SubStmt) { |
| 760 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 761 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 763 | /// \brief Build a new "if" statement. |
| 764 | /// |
| 765 | /// By default, performs semantic analysis to build the new statement. |
| 766 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 767 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 768 | VarDecl *CondVar, StmtArg Then, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 769 | SourceLocation ElseLoc, StmtArg Else) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 770 | return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 771 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 772 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 774 | /// \brief Start building a new switch statement. |
| 775 | /// |
| 776 | /// By default, performs semantic analysis to build the new statement. |
| 777 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 778 | OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 779 | Sema::ExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 780 | VarDecl *CondVar) { |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 781 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 782 | CondVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 783 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 784 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 785 | /// \brief Attach the body to the switch statement. |
| 786 | /// |
| 787 | /// By default, performs semantic analysis to build the new statement. |
| 788 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 789 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 790 | StmtArg Switch, StmtArg Body) { |
| 791 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 792 | move(Body)); |
| 793 | } |
| 794 | |
| 795 | /// \brief Build a new while statement. |
| 796 | /// |
| 797 | /// By default, performs semantic analysis to build the new statement. |
| 798 | /// Subclasses may override this routine to provide different behavior. |
| 799 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 800 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 801 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 802 | StmtArg Body) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 803 | return getSema().ActOnWhileStmt(WhileLoc, Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 804 | CondVar, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 807 | /// \brief Build a new do-while statement. |
| 808 | /// |
| 809 | /// By default, performs semantic analysis to build the new statement. |
| 810 | /// Subclasses may override this routine to provide different behavior. |
| 811 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 812 | SourceLocation WhileLoc, |
| 813 | SourceLocation LParenLoc, |
| 814 | ExprArg Cond, |
| 815 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 817 | move(Cond), RParenLoc); |
| 818 | } |
| 819 | |
| 820 | /// \brief Build a new for statement. |
| 821 | /// |
| 822 | /// By default, performs semantic analysis to build the new statement. |
| 823 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 824 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 825 | SourceLocation LParenLoc, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 826 | StmtArg Init, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 827 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 828 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 829 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 830 | CondVar, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 831 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 834 | /// \brief Build a new goto statement. |
| 835 | /// |
| 836 | /// By default, performs semantic analysis to build the new statement. |
| 837 | /// Subclasses may override this routine to provide different behavior. |
| 838 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 839 | SourceLocation LabelLoc, |
| 840 | LabelStmt *Label) { |
| 841 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 842 | } |
| 843 | |
| 844 | /// \brief Build a new indirect goto statement. |
| 845 | /// |
| 846 | /// By default, performs semantic analysis to build the new statement. |
| 847 | /// Subclasses may override this routine to provide different behavior. |
| 848 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 849 | SourceLocation StarLoc, |
| 850 | ExprArg Target) { |
| 851 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 852 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 854 | /// \brief Build a new return statement. |
| 855 | /// |
| 856 | /// By default, performs semantic analysis to build the new statement. |
| 857 | /// Subclasses may override this routine to provide different behavior. |
| 858 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 859 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 861 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 864 | /// \brief Build a new declaration statement. |
| 865 | /// |
| 866 | /// By default, performs semantic analysis to build the new statement. |
| 867 | /// Subclasses may override this routine to provide different behavior. |
| 868 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 870 | SourceLocation EndLoc) { |
| 871 | return getSema().Owned( |
| 872 | new (getSema().Context) DeclStmt( |
| 873 | DeclGroupRef::Create(getSema().Context, |
| 874 | Decls, NumDecls), |
| 875 | StartLoc, EndLoc)); |
| 876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 878 | /// \brief Build a new inline asm statement. |
| 879 | /// |
| 880 | /// By default, performs semantic analysis to build the new statement. |
| 881 | /// Subclasses may override this routine to provide different behavior. |
| 882 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 883 | bool IsSimple, |
| 884 | bool IsVolatile, |
| 885 | unsigned NumOutputs, |
| 886 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 887 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 888 | MultiExprArg Constraints, |
| 889 | MultiExprArg Exprs, |
| 890 | ExprArg AsmString, |
| 891 | MultiExprArg Clobbers, |
| 892 | SourceLocation RParenLoc, |
| 893 | bool MSAsm) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 894 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 895 | NumInputs, Names, move(Constraints), |
| 896 | move(Exprs), move(AsmString), move(Clobbers), |
| 897 | RParenLoc, MSAsm); |
| 898 | } |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 899 | |
| 900 | /// \brief Build a new Objective-C @try statement. |
| 901 | /// |
| 902 | /// By default, performs semantic analysis to build the new statement. |
| 903 | /// Subclasses may override this routine to provide different behavior. |
| 904 | OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 905 | StmtArg TryBody, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 906 | MultiStmtArg CatchStmts, |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 907 | StmtArg Finally) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 908 | return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 909 | move(Finally)); |
| 910 | } |
| 911 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 912 | /// \brief Rebuild an Objective-C exception declaration. |
| 913 | /// |
| 914 | /// By default, performs semantic analysis to build the new declaration. |
| 915 | /// Subclasses may override this routine to provide different behavior. |
| 916 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 917 | TypeSourceInfo *TInfo, QualType T) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 918 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 919 | ExceptionDecl->getIdentifier(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 920 | ExceptionDecl->getLocation()); |
| 921 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 922 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 923 | /// \brief Build a new Objective-C @catch statement. |
| 924 | /// |
| 925 | /// By default, performs semantic analysis to build the new statement. |
| 926 | /// Subclasses may override this routine to provide different behavior. |
| 927 | OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 928 | SourceLocation RParenLoc, |
| 929 | VarDecl *Var, |
| 930 | StmtArg Body) { |
| 931 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 932 | Var, move(Body)); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 933 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 934 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 935 | /// \brief Build a new Objective-C @finally statement. |
| 936 | /// |
| 937 | /// By default, performs semantic analysis to build the new statement. |
| 938 | /// Subclasses may override this routine to provide different behavior. |
| 939 | OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 940 | StmtArg Body) { |
| 941 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); |
| 942 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 944 | /// \brief Build a new Objective-C @throw statement. |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 945 | /// |
| 946 | /// By default, performs semantic analysis to build the new statement. |
| 947 | /// Subclasses may override this routine to provide different behavior. |
| 948 | OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 949 | ExprArg Operand) { |
| 950 | return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); |
| 951 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 952 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 953 | /// \brief Build a new Objective-C @synchronized statement. |
| 954 | /// |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 955 | /// By default, performs semantic analysis to build the new statement. |
| 956 | /// Subclasses may override this routine to provide different behavior. |
| 957 | OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 958 | ExprArg Object, |
| 959 | StmtArg Body) { |
| 960 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), |
| 961 | move(Body)); |
| 962 | } |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 963 | |
| 964 | /// \brief Build a new Objective-C fast enumeration statement. |
| 965 | /// |
| 966 | /// By default, performs semantic analysis to build the new statement. |
| 967 | /// Subclasses may override this routine to provide different behavior. |
| 968 | OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 969 | SourceLocation LParenLoc, |
| 970 | StmtArg Element, |
| 971 | ExprArg Collection, |
| 972 | SourceLocation RParenLoc, |
| 973 | StmtArg Body) { |
| 974 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 975 | move(Element), |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 976 | move(Collection), |
| 977 | RParenLoc, |
| 978 | move(Body)); |
| 979 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 980 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 981 | /// \brief Build a new C++ exception declaration. |
| 982 | /// |
| 983 | /// By default, performs semantic analysis to build the new decaration. |
| 984 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 986 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 987 | IdentifierInfo *Name, |
| 988 | SourceLocation Loc, |
| 989 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 991 | TypeRange); |
| 992 | } |
| 993 | |
| 994 | /// \brief Build a new C++ catch statement. |
| 995 | /// |
| 996 | /// By default, performs semantic analysis to build the new statement. |
| 997 | /// Subclasses may override this routine to provide different behavior. |
| 998 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 999 | VarDecl *ExceptionDecl, |
| 1000 | StmtArg Handler) { |
| 1001 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1003 | Handler.takeAs<Stmt>())); |
| 1004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1006 | /// \brief Build a new C++ try statement. |
| 1007 | /// |
| 1008 | /// By default, performs semantic analysis to build the new statement. |
| 1009 | /// Subclasses may override this routine to provide different behavior. |
| 1010 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 1011 | StmtArg TryBlock, |
| 1012 | MultiStmtArg Handlers) { |
| 1013 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 1014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | /// \brief Build a new expression that references a declaration. |
| 1017 | /// |
| 1018 | /// By default, performs semantic analysis to build the new expression. |
| 1019 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1020 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 1021 | LookupResult &R, |
| 1022 | bool RequiresADL) { |
| 1023 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 1024 | } |
| 1025 | |
| 1026 | |
| 1027 | /// \brief Build a new expression that references a declaration. |
| 1028 | /// |
| 1029 | /// By default, performs semantic analysis to build the new expression. |
| 1030 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1031 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 1032 | SourceRange QualifierRange, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1033 | ValueDecl *VD, |
| 1034 | const DeclarationNameInfo &NameInfo, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1035 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 1036 | CXXScopeSpec SS; |
| 1037 | SS.setScopeRep(Qualifier); |
| 1038 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 1039 | |
| 1040 | // FIXME: loses template args. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1041 | |
| 1042 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1044 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | /// By default, performs semantic analysis to build the new expression. |
| 1048 | /// Subclasses may override this routine to provide different behavior. |
| 1049 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 1050 | SourceLocation RParen) { |
| 1051 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 1052 | } |
| 1053 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1054 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 1056 | /// By default, performs semantic analysis to build the new expression. |
| 1057 | /// Subclasses may override this routine to provide different behavior. |
| 1058 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 1059 | SourceLocation OperatorLoc, |
| 1060 | bool isArrow, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1061 | NestedNameSpecifier *Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 1062 | SourceRange QualifierRange, |
| 1063 | TypeSourceInfo *ScopeType, |
| 1064 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 1065 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 1066 | PseudoDestructorTypeStorage Destroyed); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1069 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | /// By default, performs semantic analysis to build the new expression. |
| 1071 | /// Subclasses may override this routine to provide different behavior. |
| 1072 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 1073 | UnaryOperator::Opcode Opc, |
| 1074 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1075 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 1078 | /// \brief Build a new builtin offsetof expression. |
| 1079 | /// |
| 1080 | /// By default, performs semantic analysis to build the new expression. |
| 1081 | /// Subclasses may override this routine to provide different behavior. |
| 1082 | OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 1083 | TypeSourceInfo *Type, |
| 1084 | Action::OffsetOfComponent *Components, |
| 1085 | unsigned NumComponents, |
| 1086 | SourceLocation RParenLoc) { |
| 1087 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 1088 | NumComponents, RParenLoc); |
| 1089 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1091 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | /// By default, performs semantic analysis to build the new expression. |
| 1094 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1095 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 1096 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1098 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1102 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | /// By default, performs semantic analysis to build the new expression. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
| 1106 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 1107 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 1110 | OpLoc, isSizeOf, R); |
| 1111 | if (Result.isInvalid()) |
| 1112 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1114 | SubExpr.release(); |
| 1115 | return move(Result); |
| 1116 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// By default, performs semantic analysis to build the new expression. |
| 1121 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1123 | SourceLocation LBracketLoc, |
| 1124 | ExprArg RHS, |
| 1125 | SourceLocation RBracketLoc) { |
| 1126 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | RBracketLoc); |
| 1129 | } |
| 1130 | |
| 1131 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1133 | /// By default, performs semantic analysis to build the new expression. |
| 1134 | /// Subclasses may override this routine to provide different behavior. |
| 1135 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 1136 | MultiExprArg Args, |
| 1137 | SourceLocation *CommaLocs, |
| 1138 | SourceLocation RParenLoc) { |
| 1139 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 1140 | move(Args), CommaLocs, RParenLoc); |
| 1141 | } |
| 1142 | |
| 1143 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1145 | /// By default, performs semantic analysis to build the new expression. |
| 1146 | /// Subclasses may override this routine to provide different behavior. |
| 1147 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1149 | NestedNameSpecifier *Qualifier, |
| 1150 | SourceRange QualifierRange, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1151 | const DeclarationNameInfo &MemberNameInfo, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 1152 | ValueDecl *Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1153 | NamedDecl *FoundDecl, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1154 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 1155 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1156 | if (!Member->getDeclName()) { |
| 1157 | // We have a reference to an unnamed field. |
| 1158 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1160 | Expr *BaseExpr = Base.takeAs<Expr>(); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1161 | if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, |
| 1162 | FoundDecl, Member)) |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1163 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 1164 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1165 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 1166 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1167 | Member, MemberNameInfo, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1168 | cast<FieldDecl>(Member)->getType()); |
| 1169 | return getSema().Owned(ME); |
| 1170 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 1172 | CXXScopeSpec SS; |
| 1173 | if (Qualifier) { |
| 1174 | SS.setRange(QualifierRange); |
| 1175 | SS.setScopeRep(Qualifier); |
| 1176 | } |
| 1177 | |
Douglas Gregor | ef4a2a2 | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1178 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 1179 | getSema().DefaultFunctionArrayConversion(BaseExpr); |
| 1180 | QualType BaseType = BaseExpr->getType(); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1181 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1182 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 1183 | // cases; we should avoid this when possible. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1184 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 1185 | R.addDecl(FoundDecl); |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1186 | R.resolveKind(); |
| 1187 | |
Douglas Gregor | ef4a2a2 | 2010-06-22 02:41:05 +0000 | [diff] [blame] | 1188 | return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr), |
| 1189 | BaseType, OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1190 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1191 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1194 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1195 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | /// By default, performs semantic analysis to build the new expression. |
| 1197 | /// Subclasses may override this routine to provide different behavior. |
| 1198 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1199 | BinaryOperator::Opcode Opc, |
| 1200 | ExprArg LHS, ExprArg RHS) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1201 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1202 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1207 | /// By default, performs semantic analysis to build the new expression. |
| 1208 | /// Subclasses may override this routine to provide different behavior. |
| 1209 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1210 | SourceLocation QuestionLoc, |
| 1211 | ExprArg LHS, |
| 1212 | SourceLocation ColonLoc, |
| 1213 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | move(LHS), move(RHS)); |
| 1216 | } |
| 1217 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1220 | /// By default, performs semantic analysis to build the new expression. |
| 1221 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1222 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1223 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | SourceLocation RParenLoc, |
| 1225 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1226 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1227 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | /// By default, performs semantic analysis to build the new expression. |
| 1233 | /// Subclasses may override this routine to provide different behavior. |
| 1234 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1235 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | SourceLocation RParenLoc, |
| 1237 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1238 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1239 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | /// By default, performs semantic analysis to build the new expression. |
| 1245 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1247 | SourceLocation OpLoc, |
| 1248 | SourceLocation AccessorLoc, |
| 1249 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1250 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1251 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1252 | QualType BaseType = ((Expr*) Base.get())->getType(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1253 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1254 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1255 | OpLoc, /*IsArrow*/ false, |
| 1256 | SS, /*FirstQualifierInScope*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1257 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1258 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1259 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | /// By default, performs semantic analysis to build the new expression. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| 1265 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1266 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1267 | SourceLocation RBraceLoc, |
| 1268 | QualType ResultTy) { |
| 1269 | OwningExprResult Result |
| 1270 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1271 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1272 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1274 | // Patch in the result type we were given, which may have been computed |
| 1275 | // when the initial InitListExpr was built. |
| 1276 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1277 | ILE->setType(ResultTy); |
| 1278 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1281 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1283 | /// By default, performs semantic analysis to build the new expression. |
| 1284 | /// Subclasses may override this routine to provide different behavior. |
| 1285 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1286 | MultiExprArg ArrayExprs, |
| 1287 | SourceLocation EqualOrColonLoc, |
| 1288 | bool GNUSyntax, |
| 1289 | ExprArg Init) { |
| 1290 | OwningExprResult Result |
| 1291 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1292 | move(Init)); |
| 1293 | if (Result.isInvalid()) |
| 1294 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | ArrayExprs.release(); |
| 1297 | return move(Result); |
| 1298 | } |
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 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1302 | /// By default, builds the implicit value initialization without performing |
| 1303 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1304 | /// different behavior. |
| 1305 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1306 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1309 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | /// By default, performs semantic analysis to build the new expression. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 1313 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| 1314 | ExprArg SubExpr, TypeSourceInfo *TInfo, |
| 1315 | SourceLocation RParenLoc) { |
| 1316 | return getSema().BuildVAArgExpr(BuiltinLoc, |
| 1317 | move(SubExpr), TInfo, |
| 1318 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | /// By default, performs semantic analysis to build the new expression. |
| 1324 | /// Subclasses may override this routine to provide different behavior. |
| 1325 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1326 | MultiExprArg SubExprs, |
| 1327 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1328 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1329 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1330 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1332 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | /// |
| 1334 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | /// rather than attempting to map the label statement itself. |
| 1336 | /// Subclasses may override this routine to provide different behavior. |
| 1337 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1338 | SourceLocation LabelLoc, |
| 1339 | LabelStmt *Label) { |
| 1340 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1345 | /// By default, performs semantic analysis to build the new expression. |
| 1346 | /// Subclasses may override this routine to provide different behavior. |
| 1347 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1348 | StmtArg SubStmt, |
| 1349 | SourceLocation RParenLoc) { |
| 1350 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1354 | /// |
| 1355 | /// By default, performs semantic analysis to build the new expression. |
| 1356 | /// Subclasses may override this routine to provide different behavior. |
| 1357 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 1358 | TypeSourceInfo *TInfo1, |
| 1359 | TypeSourceInfo *TInfo2, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1360 | SourceLocation RParenLoc) { |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 1361 | return getSema().BuildTypesCompatibleExpr(BuiltinLoc, |
| 1362 | TInfo1, TInfo2, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1363 | RParenLoc); |
| 1364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1365 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1366 | /// \brief Build a new __builtin_choose_expr expression. |
| 1367 | /// |
| 1368 | /// By default, performs semantic analysis to build the new expression. |
| 1369 | /// Subclasses may override this routine to provide different behavior. |
| 1370 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1371 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1372 | SourceLocation RParenLoc) { |
| 1373 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1374 | move(Cond), move(LHS), move(RHS), |
| 1375 | RParenLoc); |
| 1376 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1378 | /// \brief Build a new overloaded operator call expression. |
| 1379 | /// |
| 1380 | /// By default, performs semantic analysis to build the new expression. |
| 1381 | /// The semantic analysis provides the behavior of template instantiation, |
| 1382 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1383 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1384 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1385 | /// provide different behavior. |
| 1386 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1387 | SourceLocation OpLoc, |
| 1388 | ExprArg Callee, |
| 1389 | ExprArg First, |
| 1390 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1391 | |
| 1392 | /// \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] | 1393 | /// reinterpret_cast. |
| 1394 | /// |
| 1395 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | /// Subclasses may override this routine to provide different behavior. |
| 1398 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1399 | Stmt::StmtClass Class, |
| 1400 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1401 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1402 | SourceLocation RAngleLoc, |
| 1403 | SourceLocation LParenLoc, |
| 1404 | ExprArg SubExpr, |
| 1405 | SourceLocation RParenLoc) { |
| 1406 | switch (Class) { |
| 1407 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1408 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1410 | move(SubExpr), RParenLoc); |
| 1411 | |
| 1412 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1413 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1415 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1418 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1419 | RAngleLoc, LParenLoc, |
| 1420 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1421 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1423 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1424 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | default: |
| 1429 | assert(false && "Invalid C++ named cast"); |
| 1430 | break; |
| 1431 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1432 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1433 | return getSema().ExprError(); |
| 1434 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1436 | /// \brief Build a new C++ static_cast expression. |
| 1437 | /// |
| 1438 | /// By default, performs semantic analysis to build the new expression. |
| 1439 | /// Subclasses may override this routine to provide different behavior. |
| 1440 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1441 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1442 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | SourceLocation RAngleLoc, |
| 1444 | SourceLocation LParenLoc, |
| 1445 | ExprArg SubExpr, |
| 1446 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1447 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1448 | TInfo, move(SubExpr), |
| 1449 | SourceRange(LAngleLoc, RAngleLoc), |
| 1450 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | /// \brief Build a new C++ dynamic_cast expression. |
| 1454 | /// |
| 1455 | /// By default, performs semantic analysis to build the new expression. |
| 1456 | /// Subclasses may override this routine to provide different behavior. |
| 1457 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1458 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1459 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | SourceLocation RAngleLoc, |
| 1461 | SourceLocation LParenLoc, |
| 1462 | ExprArg SubExpr, |
| 1463 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1464 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1465 | TInfo, move(SubExpr), |
| 1466 | SourceRange(LAngleLoc, RAngleLoc), |
| 1467 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1471 | /// |
| 1472 | /// By default, performs semantic analysis to build the new expression. |
| 1473 | /// Subclasses may override this routine to provide different behavior. |
| 1474 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1475 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1476 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1477 | SourceLocation RAngleLoc, |
| 1478 | SourceLocation LParenLoc, |
| 1479 | ExprArg SubExpr, |
| 1480 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1481 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1482 | TInfo, move(SubExpr), |
| 1483 | SourceRange(LAngleLoc, RAngleLoc), |
| 1484 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | /// \brief Build a new C++ const_cast expression. |
| 1488 | /// |
| 1489 | /// By default, performs semantic analysis to build the new expression. |
| 1490 | /// Subclasses may override this routine to provide different behavior. |
| 1491 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1492 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1493 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1494 | SourceLocation RAngleLoc, |
| 1495 | SourceLocation LParenLoc, |
| 1496 | ExprArg SubExpr, |
| 1497 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1498 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1499 | TInfo, move(SubExpr), |
| 1500 | SourceRange(LAngleLoc, RAngleLoc), |
| 1501 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1504 | /// \brief Build a new C++ functional-style cast expression. |
| 1505 | /// |
| 1506 | /// By default, performs semantic analysis to build the new expression. |
| 1507 | /// Subclasses may override this routine to provide different behavior. |
| 1508 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1509 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1510 | SourceLocation LParenLoc, |
| 1511 | ExprArg SubExpr, |
| 1512 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1513 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1514 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1515 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1516 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1517 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1518 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1519 | RParenLoc); |
| 1520 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1522 | /// \brief Build a new C++ typeid(type) expression. |
| 1523 | /// |
| 1524 | /// By default, performs semantic analysis to build the new expression. |
| 1525 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1526 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1527 | SourceLocation TypeidLoc, |
| 1528 | TypeSourceInfo *Operand, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1529 | SourceLocation RParenLoc) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1530 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1531 | RParenLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1532 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1534 | /// \brief Build a new C++ typeid(expr) expression. |
| 1535 | /// |
| 1536 | /// By default, performs semantic analysis to build the new expression. |
| 1537 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1538 | OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 1539 | SourceLocation TypeidLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1540 | ExprArg Operand, |
| 1541 | SourceLocation RParenLoc) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 1542 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), |
| 1543 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | /// \brief Build a new C++ "this" expression. |
| 1547 | /// |
| 1548 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1549 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1550 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1551 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1552 | QualType ThisType, |
| 1553 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1554 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1555 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1556 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | /// \brief Build a new C++ throw expression. |
| 1560 | /// |
| 1561 | /// By default, performs semantic analysis to build the new expression. |
| 1562 | /// Subclasses may override this routine to provide different behavior. |
| 1563 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1564 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1565 | } |
| 1566 | |
| 1567 | /// \brief Build a new C++ default-argument expression. |
| 1568 | /// |
| 1569 | /// By default, builds a new default-argument expression, which does not |
| 1570 | /// require any semantic analysis. Subclasses may override this routine to |
| 1571 | /// provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1572 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1573 | ParmVarDecl *Param) { |
| 1574 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1575 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | /// \brief Build a new C++ zero-initialization expression. |
| 1579 | /// |
| 1580 | /// By default, performs semantic analysis to build the new expression. |
| 1581 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 1582 | OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | SourceLocation LParenLoc, |
| 1584 | QualType T, |
| 1585 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1586 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1587 | T.getAsOpaquePtr(), LParenLoc, |
| 1588 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1589 | 0, RParenLoc); |
| 1590 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1591 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1592 | /// \brief Build a new C++ "new" expression. |
| 1593 | /// |
| 1594 | /// By default, performs semantic analysis to build the new expression. |
| 1595 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1596 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1597 | bool UseGlobal, |
| 1598 | SourceLocation PlacementLParen, |
| 1599 | MultiExprArg PlacementArgs, |
| 1600 | SourceLocation PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1601 | SourceRange TypeIdParens, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1602 | QualType AllocType, |
| 1603 | SourceLocation TypeLoc, |
| 1604 | SourceRange TypeRange, |
| 1605 | ExprArg ArraySize, |
| 1606 | SourceLocation ConstructorLParen, |
| 1607 | MultiExprArg ConstructorArgs, |
| 1608 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | PlacementLParen, |
| 1611 | move(PlacementArgs), |
| 1612 | PlacementRParen, |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 1613 | TypeIdParens, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | AllocType, |
| 1615 | TypeLoc, |
| 1616 | TypeRange, |
| 1617 | move(ArraySize), |
| 1618 | ConstructorLParen, |
| 1619 | move(ConstructorArgs), |
| 1620 | ConstructorRParen); |
| 1621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1623 | /// \brief Build a new C++ "delete" expression. |
| 1624 | /// |
| 1625 | /// By default, performs semantic analysis to build the new expression. |
| 1626 | /// Subclasses may override this routine to provide different behavior. |
| 1627 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1628 | bool IsGlobalDelete, |
| 1629 | bool IsArrayForm, |
| 1630 | ExprArg Operand) { |
| 1631 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1632 | move(Operand)); |
| 1633 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | /// \brief Build a new unary type trait expression. |
| 1636 | /// |
| 1637 | /// By default, performs semantic analysis to build the new expression. |
| 1638 | /// Subclasses may override this routine to provide different behavior. |
| 1639 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1640 | SourceLocation StartLoc, |
| 1641 | SourceLocation LParenLoc, |
| 1642 | QualType T, |
| 1643 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | T.getAsOpaquePtr(), RParenLoc); |
| 1646 | } |
| 1647 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | /// expression. |
| 1650 | /// |
| 1651 | /// By default, performs semantic analysis to build the new expression. |
| 1652 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1653 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | SourceRange QualifierRange, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1655 | const DeclarationNameInfo &NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1656 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1657 | CXXScopeSpec SS; |
| 1658 | SS.setRange(QualifierRange); |
| 1659 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1660 | |
| 1661 | if (TemplateArgs) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1662 | return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1663 | *TemplateArgs); |
| 1664 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1665 | return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /// \brief Build a new template-id expression. |
| 1669 | /// |
| 1670 | /// By default, performs semantic analysis to build the new expression. |
| 1671 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1672 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1673 | LookupResult &R, |
| 1674 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1675 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1676 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /// \brief Build a new object-construction expression. |
| 1680 | /// |
| 1681 | /// By default, performs semantic analysis to build the new expression. |
| 1682 | /// Subclasses may override this routine to provide different behavior. |
| 1683 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1684 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1685 | CXXConstructorDecl *Constructor, |
| 1686 | bool IsElidable, |
| 1687 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1688 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1689 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1690 | ConvertedArgs)) |
| 1691 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1693 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1694 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | /// \brief Build a new object-construction expression. |
| 1698 | /// |
| 1699 | /// By default, performs semantic analysis to build the new expression. |
| 1700 | /// Subclasses may override this routine to provide different behavior. |
| 1701 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1702 | QualType T, |
| 1703 | SourceLocation LParenLoc, |
| 1704 | MultiExprArg Args, |
| 1705 | SourceLocation *Commas, |
| 1706 | SourceLocation RParenLoc) { |
| 1707 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1708 | T.getAsOpaquePtr(), |
| 1709 | LParenLoc, |
| 1710 | move(Args), |
| 1711 | Commas, |
| 1712 | RParenLoc); |
| 1713 | } |
| 1714 | |
| 1715 | /// \brief Build a new object-construction expression. |
| 1716 | /// |
| 1717 | /// By default, performs semantic analysis to build the new expression. |
| 1718 | /// Subclasses may override this routine to provide different behavior. |
| 1719 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1720 | QualType T, |
| 1721 | SourceLocation LParenLoc, |
| 1722 | MultiExprArg Args, |
| 1723 | SourceLocation *Commas, |
| 1724 | SourceLocation RParenLoc) { |
| 1725 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1726 | /*FIXME*/LParenLoc), |
| 1727 | T.getAsOpaquePtr(), |
| 1728 | LParenLoc, |
| 1729 | move(Args), |
| 1730 | Commas, |
| 1731 | RParenLoc); |
| 1732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1734 | /// \brief Build a new member reference expression. |
| 1735 | /// |
| 1736 | /// By default, performs semantic analysis to build the new expression. |
| 1737 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1738 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1739 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1740 | bool IsArrow, |
| 1741 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1742 | NestedNameSpecifier *Qualifier, |
| 1743 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1744 | NamedDecl *FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1745 | const DeclarationNameInfo &MemberNameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1746 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1747 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1748 | SS.setRange(QualifierRange); |
| 1749 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1751 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1752 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1753 | SS, FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1754 | MemberNameInfo, |
| 1755 | TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1758 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1759 | /// |
| 1760 | /// By default, performs semantic analysis to build the new expression. |
| 1761 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1762 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1763 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1764 | SourceLocation OperatorLoc, |
| 1765 | bool IsArrow, |
| 1766 | NestedNameSpecifier *Qualifier, |
| 1767 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1768 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1769 | LookupResult &R, |
| 1770 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1771 | CXXScopeSpec SS; |
| 1772 | SS.setRange(QualifierRange); |
| 1773 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1775 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1776 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1777 | SS, FirstQualifierInScope, |
| 1778 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1779 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1780 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1781 | /// \brief Build a new Objective-C @encode expression. |
| 1782 | /// |
| 1783 | /// By default, performs semantic analysis to build the new expression. |
| 1784 | /// Subclasses may override this routine to provide different behavior. |
| 1785 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1786 | TypeSourceInfo *EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1787 | SourceLocation RParenLoc) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 1788 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1789 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1791 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1792 | /// \brief Build a new Objective-C class message. |
| 1793 | OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 1794 | Selector Sel, |
| 1795 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1796 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1797 | MultiExprArg Args, |
| 1798 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1799 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 1800 | ReceiverTypeInfo->getType(), |
| 1801 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1802 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1803 | move(Args)); |
| 1804 | } |
| 1805 | |
| 1806 | /// \brief Build a new Objective-C instance message. |
| 1807 | OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, |
| 1808 | Selector Sel, |
| 1809 | ObjCMethodDecl *Method, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1810 | SourceLocation LBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1811 | MultiExprArg Args, |
| 1812 | SourceLocation RBracLoc) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1813 | QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType(); |
| 1814 | return SemaRef.BuildInstanceMessage(move(Receiver), |
| 1815 | ReceiverType, |
| 1816 | /*SuperLoc=*/SourceLocation(), |
Douglas Gregor | b5186b1 | 2010-04-22 17:01:48 +0000 | [diff] [blame] | 1817 | Sel, Method, LBracLoc, RBracLoc, |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 1818 | move(Args)); |
| 1819 | } |
| 1820 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1821 | /// \brief Build a new Objective-C ivar reference expression. |
| 1822 | /// |
| 1823 | /// By default, performs semantic analysis to build the new expression. |
| 1824 | /// Subclasses may override this routine to provide different behavior. |
| 1825 | OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, |
| 1826 | SourceLocation IvarLoc, |
| 1827 | bool IsArrow, bool IsFreeIvar) { |
| 1828 | // FIXME: We lose track of the IsFreeIvar bit. |
| 1829 | CXXScopeSpec SS; |
| 1830 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1831 | LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, |
| 1832 | Sema::LookupMemberName); |
| 1833 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1834 | /*FIME:*/IvarLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 1835 | SS, 0, |
John McCall | e9cccd8 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 1836 | false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1837 | if (Result.isInvalid()) |
| 1838 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1839 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1840 | if (Result.get()) |
| 1841 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1842 | |
| 1843 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1844 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1845 | /*FIXME:*/IvarLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1846 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1847 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1848 | /*TemplateArgs=*/0); |
| 1849 | } |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1850 | |
| 1851 | /// \brief Build a new Objective-C property reference expression. |
| 1852 | /// |
| 1853 | /// By default, performs semantic analysis to build the new expression. |
| 1854 | /// Subclasses may override this routine to provide different behavior. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1855 | OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1856 | ObjCPropertyDecl *Property, |
| 1857 | SourceLocation PropertyLoc) { |
| 1858 | CXXScopeSpec SS; |
| 1859 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1860 | LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, |
| 1861 | Sema::LookupMemberName); |
| 1862 | bool IsArrow = false; |
| 1863 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1864 | /*FIME:*/PropertyLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 1865 | SS, 0, false); |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1866 | if (Result.isInvalid()) |
| 1867 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1869 | if (Result.get()) |
| 1870 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1871 | |
| 1872 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1873 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1874 | /*FIXME:*/PropertyLoc, IsArrow, |
| 1875 | SS, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1876 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1877 | R, |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 1878 | /*TemplateArgs=*/0); |
| 1879 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1880 | |
| 1881 | /// \brief Build a new Objective-C implicit setter/getter reference |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1882 | /// expression. |
| 1883 | /// |
| 1884 | /// By default, performs semantic analysis to build the new expression. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1885 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 1886 | OwningExprResult RebuildObjCImplicitSetterGetterRefExpr( |
| 1887 | ObjCMethodDecl *Getter, |
| 1888 | QualType T, |
| 1889 | ObjCMethodDecl *Setter, |
| 1890 | SourceLocation NameLoc, |
| 1891 | ExprArg Base) { |
| 1892 | // Since these expressions can only be value-dependent, we do not need to |
| 1893 | // perform semantic analysis again. |
| 1894 | return getSema().Owned( |
| 1895 | new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, |
| 1896 | Setter, |
| 1897 | NameLoc, |
| 1898 | Base.takeAs<Expr>())); |
| 1899 | } |
| 1900 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1901 | /// \brief Build a new Objective-C "isa" expression. |
| 1902 | /// |
| 1903 | /// By default, performs semantic analysis to build the new expression. |
| 1904 | /// Subclasses may override this routine to provide different behavior. |
| 1905 | OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, |
| 1906 | bool IsArrow) { |
| 1907 | CXXScopeSpec SS; |
| 1908 | Expr *Base = BaseArg.takeAs<Expr>(); |
| 1909 | LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, |
| 1910 | Sema::LookupMemberName); |
| 1911 | OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, |
| 1912 | /*FIME:*/IsaLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame^] | 1913 | SS, 0, false); |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1914 | if (Result.isInvalid()) |
| 1915 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1917 | if (Result.get()) |
| 1918 | return move(Result); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1919 | |
| 1920 | return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1921 | Base->getType(), |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1922 | /*FIXME:*/IsaLoc, IsArrow, SS, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1923 | /*FirstQualifierInScope=*/0, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1924 | R, |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 1925 | /*TemplateArgs=*/0); |
| 1926 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1928 | /// \brief Build a new shuffle vector expression. |
| 1929 | /// |
| 1930 | /// By default, performs semantic analysis to build the new expression. |
| 1931 | /// Subclasses may override this routine to provide different behavior. |
| 1932 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1933 | MultiExprArg SubExprs, |
| 1934 | SourceLocation RParenLoc) { |
| 1935 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1936 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1937 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1938 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1939 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1940 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1941 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1942 | // Build a reference to the __builtin_shufflevector builtin |
| 1943 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1944 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1945 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1946 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1947 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1948 | |
| 1949 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1950 | unsigned NumSubExprs = SubExprs.size(); |
| 1951 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1952 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1953 | Subs, NumSubExprs, |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 1954 | Builtin->getCallResultType(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1955 | RParenLoc); |
| 1956 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1958 | // Type-check the __builtin_shufflevector expression. |
| 1959 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1960 | if (Result.isInvalid()) |
| 1961 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1963 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1964 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1965 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1966 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1967 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1968 | template<typename Derived> |
| 1969 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1970 | if (!S) |
| 1971 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1973 | switch (S->getStmtClass()) { |
| 1974 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1975 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1976 | // Transform individual statement nodes |
| 1977 | #define STMT(Node, Parent) \ |
| 1978 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1979 | #define EXPR(Node, Parent) |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1980 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1981 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1982 | // Transform expressions by calling TransformExpr. |
| 1983 | #define STMT(Node, Parent) |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 1984 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1985 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1986 | #include "clang/AST/StmtNodes.inc" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1987 | { |
| 1988 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1989 | if (E.isInvalid()) |
| 1990 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1991 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1992 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1993 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1996 | return SemaRef.Owned(S->Retain()); |
| 1997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1998 | |
| 1999 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2000 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2001 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2002 | if (!E) |
| 2003 | return SemaRef.Owned(E); |
| 2004 | |
| 2005 | switch (E->getStmtClass()) { |
| 2006 | case Stmt::NoStmtClass: break; |
| 2007 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 2008 | #define ABSTRACT_STMT(Stmt) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2009 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 2010 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 2011 | #include "clang/AST/StmtNodes.inc" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2014 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2018 | NestedNameSpecifier * |
| 2019 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2020 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2021 | QualType ObjectType, |
| 2022 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 2023 | if (!NNS) |
| 2024 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2026 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2027 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 2028 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2030 | ObjectType, |
| 2031 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2032 | if (!Prefix) |
| 2033 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | |
| 2035 | // 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] | 2036 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2037 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2038 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2039 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2041 | switch (NNS->getKind()) { |
| 2042 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2043 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2044 | "Identifier nested-name-specifier with no prefix or object type"); |
| 2045 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 2046 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2047 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
| 2049 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 2050 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 2051 | ObjectType, |
| 2052 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2053 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2054 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2055 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2056 | = cast_or_null<NamespaceDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2057 | getDerived().TransformDecl(Range.getBegin(), |
| 2058 | NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2059 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2060 | Prefix == NNS->getPrefix() && |
| 2061 | NS == NNS->getAsNamespace()) |
| 2062 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2063 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2064 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 2065 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2066 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2067 | case NestedNameSpecifier::Global: |
| 2068 | // There is no meaningful transformation that one could perform on the |
| 2069 | // global scope. |
| 2070 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2071 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2072 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2073 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 2074 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2075 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 2076 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2077 | if (T.isNull()) |
| 2078 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2079 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2080 | if (!getDerived().AlwaysRebuild() && |
| 2081 | Prefix == NNS->getPrefix() && |
| 2082 | T == QualType(NNS->getAsType(), 0)) |
| 2083 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2084 | |
| 2085 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 2086 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 2087 | T); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2088 | } |
| 2089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2090 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2091 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2092 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | template<typename Derived> |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2096 | DeclarationNameInfo |
| 2097 | TreeTransform<Derived> |
| 2098 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 2099 | QualType ObjectType) { |
| 2100 | DeclarationName Name = NameInfo.getName(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2101 | if (!Name) |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2102 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2103 | |
| 2104 | switch (Name.getNameKind()) { |
| 2105 | case DeclarationName::Identifier: |
| 2106 | case DeclarationName::ObjCZeroArgSelector: |
| 2107 | case DeclarationName::ObjCOneArgSelector: |
| 2108 | case DeclarationName::ObjCMultiArgSelector: |
| 2109 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2110 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2111 | case DeclarationName::CXXUsingDirective: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2112 | return NameInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2113 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2114 | case DeclarationName::CXXConstructorName: |
| 2115 | case DeclarationName::CXXDestructorName: |
| 2116 | case DeclarationName::CXXConversionFunctionName: { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2117 | TypeSourceInfo *NewTInfo; |
| 2118 | CanQualType NewCanTy; |
| 2119 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| 2120 | NewTInfo = getDerived().TransformType(OldTInfo, ObjectType); |
| 2121 | if (!NewTInfo) |
| 2122 | return DeclarationNameInfo(); |
| 2123 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| 2124 | } |
| 2125 | else { |
| 2126 | NewTInfo = 0; |
| 2127 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| 2128 | QualType NewT = getDerived().TransformType(Name.getCXXNameType(), |
| 2129 | ObjectType); |
| 2130 | if (NewT.isNull()) |
| 2131 | return DeclarationNameInfo(); |
| 2132 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 2133 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2134 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2135 | DeclarationName NewName |
| 2136 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 2137 | NewCanTy); |
| 2138 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 2139 | NewNameInfo.setName(NewName); |
| 2140 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 2141 | return NewNameInfo; |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2145 | assert(0 && "Unknown name kind."); |
| 2146 | return DeclarationNameInfo(); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2150 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2151 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 2152 | QualType ObjectType) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2153 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2154 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2155 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2156 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2157 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2158 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2159 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2160 | if (!NNS) |
| 2161 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2162 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2163 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2164 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2165 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2166 | if (!TransTemplate) |
| 2167 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2169 | if (!getDerived().AlwaysRebuild() && |
| 2170 | NNS == QTN->getQualifier() && |
| 2171 | TransTemplate == Template) |
| 2172 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2173 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2174 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 2175 | TransTemplate); |
| 2176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2177 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2178 | // These should be getting filtered out before they make it into the AST. |
| 2179 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2180 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2181 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2182 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2183 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2184 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2185 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 2186 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2187 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2188 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2189 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2190 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2191 | NNS == DTN->getQualifier() && |
| 2192 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2193 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2194 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2195 | if (DTN->isIdentifier()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2196 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2197 | ObjectType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2198 | |
| 2199 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2200 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2202 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2203 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | TemplateDecl *TransTemplate |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2205 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2206 | if (!TransTemplate) |
| 2207 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2209 | if (!getDerived().AlwaysRebuild() && |
| 2210 | TransTemplate == Template) |
| 2211 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2213 | return TemplateName(TransTemplate); |
| 2214 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2215 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2216 | // These should be getting filtered out before they reach the AST. |
| 2217 | assert(false && "overloaded function decl survived to here"); |
| 2218 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2222 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 2223 | const TemplateArgument &Arg, |
| 2224 | TemplateArgumentLoc &Output) { |
| 2225 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 2226 | switch (Arg.getKind()) { |
| 2227 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2228 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2229 | break; |
| 2230 | |
| 2231 | case TemplateArgument::Type: |
| 2232 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2233 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2234 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2235 | break; |
| 2236 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2237 | case TemplateArgument::Template: |
| 2238 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 2239 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2240 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2241 | case TemplateArgument::Expression: |
| 2242 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 2243 | break; |
| 2244 | |
| 2245 | case TemplateArgument::Declaration: |
| 2246 | case TemplateArgument::Integral: |
| 2247 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2248 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2249 | break; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | template<typename Derived> |
| 2254 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 2255 | const TemplateArgumentLoc &Input, |
| 2256 | TemplateArgumentLoc &Output) { |
| 2257 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2258 | switch (Arg.getKind()) { |
| 2259 | case TemplateArgument::Null: |
| 2260 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2261 | Output = Input; |
| 2262 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2263 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2264 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2265 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2266 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2267 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2268 | |
| 2269 | DI = getDerived().TransformType(DI); |
| 2270 | if (!DI) return true; |
| 2271 | |
| 2272 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 2273 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2275 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2276 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2277 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2278 | DeclarationName Name; |
| 2279 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2280 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2281 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2282 | Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2283 | if (!D) return true; |
| 2284 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2285 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2286 | if (SourceExpr) { |
| 2287 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2288 | Action::Unevaluated); |
| 2289 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2290 | if (E.isInvalid()) |
| 2291 | SourceExpr = NULL; |
| 2292 | else { |
| 2293 | SourceExpr = E.takeAs<Expr>(); |
| 2294 | SourceExpr->Retain(); |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2299 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2301 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2302 | case TemplateArgument::Template: { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2303 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2304 | TemplateName Template |
| 2305 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2306 | if (Template.isNull()) |
| 2307 | return true; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2308 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2309 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2310 | Input.getTemplateQualifierRange(), |
| 2311 | Input.getTemplateNameLoc()); |
| 2312 | return false; |
| 2313 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2314 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2315 | case TemplateArgument::Expression: { |
| 2316 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2317 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2318 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2319 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2320 | Expr *InputExpr = Input.getSourceExpression(); |
| 2321 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2322 | |
| 2323 | Sema::OwningExprResult E |
| 2324 | = getDerived().TransformExpr(InputExpr); |
| 2325 | if (E.isInvalid()) return true; |
| 2326 | |
| 2327 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2328 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2329 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2330 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2331 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2332 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2333 | case TemplateArgument::Pack: { |
| 2334 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2335 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2336 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2337 | AEnd = Arg.pack_end(); |
| 2338 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2339 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2340 | // FIXME: preserve source information here when we start |
| 2341 | // caring about parameter packs. |
| 2342 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2343 | TemplateArgumentLoc InputArg; |
| 2344 | TemplateArgumentLoc OutputArg; |
| 2345 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2346 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2347 | return true; |
| 2348 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2349 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2350 | } |
| 2351 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2352 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2353 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2354 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2355 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2356 | } |
| 2357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2358 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2359 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2360 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2363 | //===----------------------------------------------------------------------===// |
| 2364 | // Type transformation |
| 2365 | //===----------------------------------------------------------------------===// |
| 2366 | |
| 2367 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2368 | QualType TreeTransform<Derived>::TransformType(QualType T, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2369 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2370 | if (getDerived().AlreadyTransformed(T)) |
| 2371 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2372 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2373 | // Temporary workaround. All of these transformations should |
| 2374 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2375 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2376 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2377 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2378 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2379 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2380 | if (!NewDI) |
| 2381 | return QualType(); |
| 2382 | |
| 2383 | return NewDI->getType(); |
| 2384 | } |
| 2385 | |
| 2386 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2387 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2388 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2389 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2390 | return DI; |
| 2391 | |
| 2392 | TypeLocBuilder TLB; |
| 2393 | |
| 2394 | TypeLoc TL = DI->getTypeLoc(); |
| 2395 | TLB.reserve(TL.getFullDataSize()); |
| 2396 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2397 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2398 | if (Result.isNull()) |
| 2399 | return 0; |
| 2400 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2401 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | template<typename Derived> |
| 2405 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2406 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2407 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2408 | switch (T.getTypeLocClass()) { |
| 2409 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2410 | #define TYPELOC(CLASS, PARENT) \ |
| 2411 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2412 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2413 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2414 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2416 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2417 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | return QualType(); |
| 2419 | } |
| 2420 | |
| 2421 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2422 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2423 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2424 | /// types). This is the right thing for template instantiation, but |
| 2425 | /// probably not for other clients. |
| 2426 | template<typename Derived> |
| 2427 | QualType |
| 2428 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2429 | QualifiedTypeLoc T, |
| 2430 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2431 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2432 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2433 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2434 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2435 | if (Result.isNull()) |
| 2436 | return QualType(); |
| 2437 | |
| 2438 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2439 | // FIXME: this is the right thing for template instantiation, but |
| 2440 | // probably not for other clients. |
| 2441 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2442 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2443 | |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 2444 | if (!Quals.empty()) { |
| 2445 | Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 2446 | TLB.push<QualifiedTypeLoc>(Result); |
| 2447 | // No location information to preserve. |
| 2448 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2449 | |
| 2450 | return Result; |
| 2451 | } |
| 2452 | |
| 2453 | template <class TyLoc> static inline |
| 2454 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2455 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2456 | NewT.setNameLoc(T.getNameLoc()); |
| 2457 | return T.getType(); |
| 2458 | } |
| 2459 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2460 | template<typename Derived> |
| 2461 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2462 | BuiltinTypeLoc T, |
| 2463 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2464 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2465 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2466 | if (T.needsExtraLocalData()) |
| 2467 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2468 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2469 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2470 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2471 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2472 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2473 | ComplexTypeLoc T, |
| 2474 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2475 | // FIXME: recurse? |
| 2476 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2477 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2478 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2479 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2480 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2481 | PointerTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2482 | QualType ObjectType) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2483 | QualType PointeeType |
| 2484 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2485 | if (PointeeType.isNull()) |
| 2486 | return QualType(); |
| 2487 | |
| 2488 | QualType Result = TL.getType(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2489 | if (PointeeType->getAs<ObjCObjectType>()) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2490 | // A dependent pointer type 'T *' has is being transformed such |
| 2491 | // that an Objective-C class type is being replaced for 'T'. The |
| 2492 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 2493 | // PointerType. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2494 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2495 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2496 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 2497 | NewT.setStarLoc(TL.getStarLoc()); |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2498 | return Result; |
| 2499 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2500 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2501 | if (getDerived().AlwaysRebuild() || |
| 2502 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2503 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 2504 | if (Result.isNull()) |
| 2505 | return QualType(); |
| 2506 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2507 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2508 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 2509 | NewT.setSigilLoc(TL.getSigilLoc()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2510 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2512 | |
| 2513 | template<typename Derived> |
| 2514 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2515 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2516 | BlockPointerTypeLoc TL, |
| 2517 | QualType ObjectType) { |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2518 | QualType PointeeType |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2519 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2520 | if (PointeeType.isNull()) |
| 2521 | return QualType(); |
| 2522 | |
| 2523 | QualType Result = TL.getType(); |
| 2524 | if (getDerived().AlwaysRebuild() || |
| 2525 | PointeeType != TL.getPointeeLoc().getType()) { |
| 2526 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2527 | TL.getSigilLoc()); |
| 2528 | if (Result.isNull()) |
| 2529 | return QualType(); |
| 2530 | } |
| 2531 | |
Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 2532 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 2533 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 2534 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2537 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2538 | /// don't care whether the type itself is an l-value type or an r-value |
| 2539 | /// type; we only care if the type was *written* as an l-value type |
| 2540 | /// or an r-value type. |
| 2541 | template<typename Derived> |
| 2542 | QualType |
| 2543 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2544 | ReferenceTypeLoc TL, |
| 2545 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2546 | const ReferenceType *T = TL.getTypePtr(); |
| 2547 | |
| 2548 | // Note that this works with the pointee-as-written. |
| 2549 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2550 | if (PointeeType.isNull()) |
| 2551 | return QualType(); |
| 2552 | |
| 2553 | QualType Result = TL.getType(); |
| 2554 | if (getDerived().AlwaysRebuild() || |
| 2555 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2556 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2557 | T->isSpelledAsLValue(), |
| 2558 | TL.getSigilLoc()); |
| 2559 | if (Result.isNull()) |
| 2560 | return QualType(); |
| 2561 | } |
| 2562 | |
| 2563 | // r-value references can be rebuilt as l-value references. |
| 2564 | ReferenceTypeLoc NewTL; |
| 2565 | if (isa<LValueReferenceType>(Result)) |
| 2566 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2567 | else |
| 2568 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2569 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2570 | |
| 2571 | return Result; |
| 2572 | } |
| 2573 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | template<typename Derived> |
| 2575 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2576 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2577 | LValueReferenceTypeLoc TL, |
| 2578 | QualType ObjectType) { |
| 2579 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2582 | template<typename Derived> |
| 2583 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2584 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2585 | RValueReferenceTypeLoc TL, |
| 2586 | QualType ObjectType) { |
| 2587 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2588 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2589 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2590 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2592 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2593 | MemberPointerTypeLoc TL, |
| 2594 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2595 | MemberPointerType *T = TL.getTypePtr(); |
| 2596 | |
| 2597 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2598 | if (PointeeType.isNull()) |
| 2599 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2600 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2601 | // TODO: preserve source information for this. |
| 2602 | QualType ClassType |
| 2603 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2604 | if (ClassType.isNull()) |
| 2605 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2606 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2607 | QualType Result = TL.getType(); |
| 2608 | if (getDerived().AlwaysRebuild() || |
| 2609 | PointeeType != T->getPointeeType() || |
| 2610 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2611 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2612 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2613 | if (Result.isNull()) |
| 2614 | return QualType(); |
| 2615 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2616 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2617 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2618 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2619 | |
| 2620 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2621 | } |
| 2622 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | template<typename Derived> |
| 2624 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2625 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2626 | ConstantArrayTypeLoc TL, |
| 2627 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2628 | ConstantArrayType *T = TL.getTypePtr(); |
| 2629 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2630 | if (ElementType.isNull()) |
| 2631 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2632 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2633 | QualType Result = TL.getType(); |
| 2634 | if (getDerived().AlwaysRebuild() || |
| 2635 | ElementType != T->getElementType()) { |
| 2636 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2637 | T->getSizeModifier(), |
| 2638 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2639 | T->getIndexTypeCVRQualifiers(), |
| 2640 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2641 | if (Result.isNull()) |
| 2642 | return QualType(); |
| 2643 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2644 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2645 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2646 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2647 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2648 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | Expr *Size = TL.getSizeExpr(); |
| 2650 | if (Size) { |
| 2651 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2652 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2653 | } |
| 2654 | NewTL.setSizeExpr(Size); |
| 2655 | |
| 2656 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2657 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2658 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2659 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2660 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2661 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2662 | IncompleteArrayTypeLoc TL, |
| 2663 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2664 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2665 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2666 | if (ElementType.isNull()) |
| 2667 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2668 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2669 | QualType Result = TL.getType(); |
| 2670 | if (getDerived().AlwaysRebuild() || |
| 2671 | ElementType != T->getElementType()) { |
| 2672 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2673 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2674 | T->getIndexTypeCVRQualifiers(), |
| 2675 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2676 | if (Result.isNull()) |
| 2677 | return QualType(); |
| 2678 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2679 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2680 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2681 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2682 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2683 | NewTL.setSizeExpr(0); |
| 2684 | |
| 2685 | return Result; |
| 2686 | } |
| 2687 | |
| 2688 | template<typename Derived> |
| 2689 | QualType |
| 2690 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2691 | VariableArrayTypeLoc TL, |
| 2692 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2693 | VariableArrayType *T = TL.getTypePtr(); |
| 2694 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2695 | if (ElementType.isNull()) |
| 2696 | return QualType(); |
| 2697 | |
| 2698 | // Array bounds are not potentially evaluated contexts |
| 2699 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2700 | |
| 2701 | Sema::OwningExprResult SizeResult |
| 2702 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2703 | if (SizeResult.isInvalid()) |
| 2704 | return QualType(); |
| 2705 | |
| 2706 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2707 | |
| 2708 | QualType Result = TL.getType(); |
| 2709 | if (getDerived().AlwaysRebuild() || |
| 2710 | ElementType != T->getElementType() || |
| 2711 | Size != T->getSizeExpr()) { |
| 2712 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2713 | T->getSizeModifier(), |
| 2714 | move(SizeResult), |
| 2715 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2716 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2717 | if (Result.isNull()) |
| 2718 | return QualType(); |
| 2719 | } |
| 2720 | else SizeResult.take(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2721 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2722 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2723 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2724 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2725 | NewTL.setSizeExpr(Size); |
| 2726 | |
| 2727 | return Result; |
| 2728 | } |
| 2729 | |
| 2730 | template<typename Derived> |
| 2731 | QualType |
| 2732 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2733 | DependentSizedArrayTypeLoc TL, |
| 2734 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2735 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2736 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2737 | if (ElementType.isNull()) |
| 2738 | return QualType(); |
| 2739 | |
| 2740 | // Array bounds are not potentially evaluated contexts |
| 2741 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2742 | |
| 2743 | Sema::OwningExprResult SizeResult |
| 2744 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2745 | if (SizeResult.isInvalid()) |
| 2746 | return QualType(); |
| 2747 | |
| 2748 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2749 | |
| 2750 | QualType Result = TL.getType(); |
| 2751 | if (getDerived().AlwaysRebuild() || |
| 2752 | ElementType != T->getElementType() || |
| 2753 | Size != T->getSizeExpr()) { |
| 2754 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2755 | T->getSizeModifier(), |
| 2756 | move(SizeResult), |
| 2757 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2758 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2759 | if (Result.isNull()) |
| 2760 | return QualType(); |
| 2761 | } |
| 2762 | else SizeResult.take(); |
| 2763 | |
| 2764 | // We might have any sort of array type now, but fortunately they |
| 2765 | // all have the same location layout. |
| 2766 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2767 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2768 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2769 | NewTL.setSizeExpr(Size); |
| 2770 | |
| 2771 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2772 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2773 | |
| 2774 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2775 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2777 | DependentSizedExtVectorTypeLoc TL, |
| 2778 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2779 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2780 | |
| 2781 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2782 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2783 | if (ElementType.isNull()) |
| 2784 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2785 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2786 | // Vector sizes are not potentially evaluated contexts |
| 2787 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2788 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2789 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2790 | if (Size.isInvalid()) |
| 2791 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2793 | QualType Result = TL.getType(); |
| 2794 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2795 | ElementType != T->getElementType() || |
| 2796 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2798 | move(Size), |
| 2799 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2800 | if (Result.isNull()) |
| 2801 | return QualType(); |
| 2802 | } |
| 2803 | else Size.take(); |
| 2804 | |
| 2805 | // Result might be dependent or not. |
| 2806 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2807 | DependentSizedExtVectorTypeLoc NewTL |
| 2808 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2809 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2810 | } else { |
| 2811 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2812 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2813 | } |
| 2814 | |
| 2815 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2816 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2817 | |
| 2818 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2819 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2820 | VectorTypeLoc TL, |
| 2821 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2822 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2823 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2824 | if (ElementType.isNull()) |
| 2825 | return QualType(); |
| 2826 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2827 | QualType Result = TL.getType(); |
| 2828 | if (getDerived().AlwaysRebuild() || |
| 2829 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2830 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2831 | T->getAltiVecSpecific()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2832 | if (Result.isNull()) |
| 2833 | return QualType(); |
| 2834 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2835 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2836 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2837 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2838 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2839 | return Result; |
| 2840 | } |
| 2841 | |
| 2842 | template<typename Derived> |
| 2843 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2844 | ExtVectorTypeLoc TL, |
| 2845 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2846 | VectorType *T = TL.getTypePtr(); |
| 2847 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2848 | if (ElementType.isNull()) |
| 2849 | return QualType(); |
| 2850 | |
| 2851 | QualType Result = TL.getType(); |
| 2852 | if (getDerived().AlwaysRebuild() || |
| 2853 | ElementType != T->getElementType()) { |
| 2854 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2855 | T->getNumElements(), |
| 2856 | /*FIXME*/ SourceLocation()); |
| 2857 | if (Result.isNull()) |
| 2858 | return QualType(); |
| 2859 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2860 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2861 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2862 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2863 | |
| 2864 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2865 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2866 | |
| 2867 | template<typename Derived> |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2868 | ParmVarDecl * |
| 2869 | TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { |
| 2870 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 2871 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
| 2872 | if (!NewDI) |
| 2873 | return 0; |
| 2874 | |
| 2875 | if (NewDI == OldDI) |
| 2876 | return OldParm; |
| 2877 | else |
| 2878 | return ParmVarDecl::Create(SemaRef.Context, |
| 2879 | OldParm->getDeclContext(), |
| 2880 | OldParm->getLocation(), |
| 2881 | OldParm->getIdentifier(), |
| 2882 | NewDI->getType(), |
| 2883 | NewDI, |
| 2884 | OldParm->getStorageClass(), |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2885 | OldParm->getStorageClassAsWritten(), |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2886 | /* DefArg */ NULL); |
| 2887 | } |
| 2888 | |
| 2889 | template<typename Derived> |
| 2890 | bool TreeTransform<Derived>:: |
| 2891 | TransformFunctionTypeParams(FunctionProtoTypeLoc TL, |
| 2892 | llvm::SmallVectorImpl<QualType> &PTypes, |
| 2893 | llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { |
| 2894 | FunctionProtoType *T = TL.getTypePtr(); |
| 2895 | |
| 2896 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2897 | ParmVarDecl *OldParm = TL.getArg(i); |
| 2898 | |
| 2899 | QualType NewType; |
| 2900 | ParmVarDecl *NewParm; |
| 2901 | |
| 2902 | if (OldParm) { |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2903 | NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 2904 | if (!NewParm) |
| 2905 | return true; |
| 2906 | NewType = NewParm->getType(); |
| 2907 | |
| 2908 | // Deal with the possibility that we don't have a parameter |
| 2909 | // declaration for this parameter. |
| 2910 | } else { |
| 2911 | NewParm = 0; |
| 2912 | |
| 2913 | QualType OldType = T->getArgType(i); |
| 2914 | NewType = getDerived().TransformType(OldType); |
| 2915 | if (NewType.isNull()) |
| 2916 | return true; |
| 2917 | } |
| 2918 | |
| 2919 | PTypes.push_back(NewType); |
| 2920 | PVars.push_back(NewParm); |
| 2921 | } |
| 2922 | |
| 2923 | return false; |
| 2924 | } |
| 2925 | |
| 2926 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2927 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2928 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2929 | FunctionProtoTypeLoc TL, |
| 2930 | QualType ObjectType) { |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2931 | // Transform the parameters. We do this first for the benefit of template |
| 2932 | // instantiations, so that the ParmVarDecls get/ placed into the template |
| 2933 | // instantiation scope before we transform the function type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2934 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2935 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 2936 | if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) |
| 2937 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2938 | |
Douglas Gregor | 14cf752 | 2010-04-30 18:55:50 +0000 | [diff] [blame] | 2939 | FunctionProtoType *T = TL.getTypePtr(); |
| 2940 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2941 | if (ResultType.isNull()) |
| 2942 | return QualType(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2943 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2944 | QualType Result = TL.getType(); |
| 2945 | if (getDerived().AlwaysRebuild() || |
| 2946 | ResultType != T->getResultType() || |
| 2947 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2948 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2949 | ParamTypes.data(), |
| 2950 | ParamTypes.size(), |
| 2951 | T->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 2952 | T->getTypeQuals(), |
| 2953 | T->getExtInfo()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2954 | if (Result.isNull()) |
| 2955 | return QualType(); |
| 2956 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2957 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2958 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2959 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2960 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2961 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2962 | NewTL.setArg(i, ParamDecls[i]); |
| 2963 | |
| 2964 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2965 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2966 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2967 | template<typename Derived> |
| 2968 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2969 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2970 | FunctionNoProtoTypeLoc TL, |
| 2971 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2972 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2973 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2974 | if (ResultType.isNull()) |
| 2975 | return QualType(); |
| 2976 | |
| 2977 | QualType Result = TL.getType(); |
| 2978 | if (getDerived().AlwaysRebuild() || |
| 2979 | ResultType != T->getResultType()) |
| 2980 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2981 | |
| 2982 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2983 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2984 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2985 | |
| 2986 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2988 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2989 | template<typename Derived> QualType |
| 2990 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2991 | UnresolvedUsingTypeLoc TL, |
| 2992 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2993 | UnresolvedUsingType *T = TL.getTypePtr(); |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 2994 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2995 | if (!D) |
| 2996 | return QualType(); |
| 2997 | |
| 2998 | QualType Result = TL.getType(); |
| 2999 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 3000 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 3001 | if (Result.isNull()) |
| 3002 | return QualType(); |
| 3003 | } |
| 3004 | |
| 3005 | // We might get an arbitrary type spec type back. We should at |
| 3006 | // least always get a type spec type, though. |
| 3007 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 3008 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3009 | |
| 3010 | return Result; |
| 3011 | } |
| 3012 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3013 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3014 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3015 | TypedefTypeLoc TL, |
| 3016 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3017 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3018 | TypedefDecl *Typedef |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3019 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3020 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3021 | if (!Typedef) |
| 3022 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3023 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3024 | QualType Result = TL.getType(); |
| 3025 | if (getDerived().AlwaysRebuild() || |
| 3026 | Typedef != T->getDecl()) { |
| 3027 | Result = getDerived().RebuildTypedefType(Typedef); |
| 3028 | if (Result.isNull()) |
| 3029 | return QualType(); |
| 3030 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3032 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 3033 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3034 | |
| 3035 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3036 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3038 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3039 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3040 | TypeOfExprTypeLoc TL, |
| 3041 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3042 | // typeof expressions are not potentially evaluated contexts |
| 3043 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3045 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3046 | if (E.isInvalid()) |
| 3047 | return QualType(); |
| 3048 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3049 | QualType Result = TL.getType(); |
| 3050 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3051 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3052 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 3053 | if (Result.isNull()) |
| 3054 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3055 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3056 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3058 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3059 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3060 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3061 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3062 | |
| 3063 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3065 | |
| 3066 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3067 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3068 | TypeOfTypeLoc TL, |
| 3069 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3070 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 3071 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 3072 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3073 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3074 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3075 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3076 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 3077 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3078 | if (Result.isNull()) |
| 3079 | return QualType(); |
| 3080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3082 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 3083 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 3084 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 3085 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 3086 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3087 | |
| 3088 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3090 | |
| 3091 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3092 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3093 | DecltypeTypeLoc TL, |
| 3094 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3095 | DecltypeType *T = TL.getTypePtr(); |
| 3096 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3097 | // decltype expressions are not potentially evaluated contexts |
| 3098 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3099 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3100 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 3101 | if (E.isInvalid()) |
| 3102 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3104 | QualType Result = TL.getType(); |
| 3105 | if (getDerived().AlwaysRebuild() || |
| 3106 | E.get() != T->getUnderlyingExpr()) { |
| 3107 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 3108 | if (Result.isNull()) |
| 3109 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3110 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3111 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3112 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3113 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 3114 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3115 | |
| 3116 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3120 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3121 | RecordTypeLoc TL, |
| 3122 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3123 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3124 | RecordDecl *Record |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3125 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3126 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3127 | if (!Record) |
| 3128 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3129 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3130 | QualType Result = TL.getType(); |
| 3131 | if (getDerived().AlwaysRebuild() || |
| 3132 | Record != T->getDecl()) { |
| 3133 | Result = getDerived().RebuildRecordType(Record); |
| 3134 | if (Result.isNull()) |
| 3135 | return QualType(); |
| 3136 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3138 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 3139 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3140 | |
| 3141 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3143 | |
| 3144 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3145 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3146 | EnumTypeLoc TL, |
| 3147 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3148 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3149 | EnumDecl *Enum |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 3150 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 3151 | T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3152 | if (!Enum) |
| 3153 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3155 | QualType Result = TL.getType(); |
| 3156 | if (getDerived().AlwaysRebuild() || |
| 3157 | Enum != T->getDecl()) { |
| 3158 | Result = getDerived().RebuildEnumType(Enum); |
| 3159 | if (Result.isNull()) |
| 3160 | return QualType(); |
| 3161 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3163 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 3164 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3165 | |
| 3166 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3167 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3168 | |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3169 | template<typename Derived> |
| 3170 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 3171 | TypeLocBuilder &TLB, |
| 3172 | InjectedClassNameTypeLoc TL, |
| 3173 | QualType ObjectType) { |
| 3174 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 3175 | TL.getTypePtr()->getDecl()); |
| 3176 | if (!D) return QualType(); |
| 3177 | |
| 3178 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 3179 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 3180 | return T; |
| 3181 | } |
| 3182 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3183 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3184 | template<typename Derived> |
| 3185 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3186 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3187 | TemplateTypeParmTypeLoc TL, |
| 3188 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3189 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3192 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3193 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3194 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3195 | SubstTemplateTypeParmTypeLoc TL, |
| 3196 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3197 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3201 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 3202 | const TemplateSpecializationType *TST, |
| 3203 | QualType ObjectType) { |
| 3204 | // FIXME: this entire method is a temporary workaround; callers |
| 3205 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3206 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3207 | // Fake up a TemplateSpecializationTypeLoc. |
| 3208 | TypeLocBuilder TLB; |
| 3209 | TemplateSpecializationTypeLoc TL |
| 3210 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 3211 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3212 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 3213 | |
| 3214 | TL.setTemplateNameLoc(BaseLoc); |
| 3215 | TL.setLAngleLoc(BaseLoc); |
| 3216 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3217 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 3218 | const TemplateArgument &TA = TST->getArg(i); |
| 3219 | TemplateArgumentLoc TAL; |
| 3220 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 3221 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 3222 | } |
| 3223 | |
| 3224 | TypeLocBuilder IgnoredTLB; |
| 3225 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3226 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3227 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3228 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3229 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3230 | TypeLocBuilder &TLB, |
| 3231 | TemplateSpecializationTypeLoc TL, |
| 3232 | QualType ObjectType) { |
| 3233 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 3234 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3235 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 3236 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3237 | if (Template.isNull()) |
| 3238 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3239 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3240 | TemplateArgumentListInfo NewTemplateArgs; |
| 3241 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3242 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3243 | |
| 3244 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 3245 | TemplateArgumentLoc Loc; |
| 3246 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3247 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3248 | NewTemplateArgs.addArgument(Loc); |
| 3249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3251 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 3252 | |
| 3253 | QualType Result = |
| 3254 | getDerived().RebuildTemplateSpecializationType(Template, |
| 3255 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3256 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3257 | |
| 3258 | if (!Result.isNull()) { |
| 3259 | TemplateSpecializationTypeLoc NewTL |
| 3260 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 3261 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 3262 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3263 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3264 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 3265 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3268 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3269 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | |
| 3271 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3272 | QualType |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3273 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 3274 | ElaboratedTypeLoc TL, |
| 3275 | QualType ObjectType) { |
| 3276 | ElaboratedType *T = TL.getTypePtr(); |
| 3277 | |
| 3278 | NestedNameSpecifier *NNS = 0; |
| 3279 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 3280 | if (T->getQualifier() != 0) { |
| 3281 | NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3282 | TL.getQualifierRange(), |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3283 | ObjectType); |
| 3284 | if (!NNS) |
| 3285 | return QualType(); |
| 3286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3288 | QualType NamedT; |
| 3289 | // FIXME: this test is meant to workaround a problem (failing assertion) |
| 3290 | // occurring if directly executing the code in the else branch. |
| 3291 | if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) { |
| 3292 | TemplateSpecializationTypeLoc OldNamedTL |
| 3293 | = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc()); |
| 3294 | const TemplateSpecializationType* OldTST |
Jim Grosbach | db06151 | 2010-05-19 23:53:08 +0000 | [diff] [blame] | 3295 | = OldNamedTL.getType()->template getAs<TemplateSpecializationType>(); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3296 | NamedT = TransformTemplateSpecializationType(OldTST, ObjectType); |
| 3297 | if (NamedT.isNull()) |
| 3298 | return QualType(); |
| 3299 | TemplateSpecializationTypeLoc NewNamedTL |
| 3300 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3301 | NewNamedTL.copy(OldNamedTL); |
| 3302 | } |
| 3303 | else { |
| 3304 | NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 3305 | if (NamedT.isNull()) |
| 3306 | return QualType(); |
| 3307 | } |
Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 3308 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3309 | QualType Result = TL.getType(); |
| 3310 | if (getDerived().AlwaysRebuild() || |
| 3311 | NNS != T->getQualifier() || |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3312 | NamedT != T->getNamedType()) { |
| 3313 | Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3314 | if (Result.isNull()) |
| 3315 | return QualType(); |
| 3316 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3317 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3318 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3319 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3320 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3321 | |
| 3322 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3323 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | |
| 3325 | template<typename Derived> |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3326 | QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, |
| 3327 | DependentNameTypeLoc TL, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3328 | QualType ObjectType) { |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3329 | DependentNameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3330 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3331 | NestedNameSpecifier *NNS |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3332 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3333 | TL.getQualifierRange(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 3334 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3335 | if (!NNS) |
| 3336 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3338 | QualType Result |
| 3339 | = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, |
| 3340 | T->getIdentifier(), |
| 3341 | TL.getKeywordLoc(), |
| 3342 | TL.getQualifierRange(), |
| 3343 | TL.getNameLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3344 | if (Result.isNull()) |
| 3345 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3346 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3347 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 3348 | QualType NamedT = ElabT->getNamedType(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3349 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 3350 | |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3351 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3352 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3353 | NewTL.setQualifierRange(TL.getQualifierRange()); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3354 | } else { |
Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 3355 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 3356 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3357 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3358 | NewTL.setNameLoc(TL.getNameLoc()); |
| 3359 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3360 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3361 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3363 | template<typename Derived> |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3364 | QualType TreeTransform<Derived>:: |
| 3365 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 3366 | DependentTemplateSpecializationTypeLoc TL, |
| 3367 | QualType ObjectType) { |
| 3368 | DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 3369 | |
| 3370 | NestedNameSpecifier *NNS |
| 3371 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 3372 | TL.getQualifierRange(), |
| 3373 | ObjectType); |
| 3374 | if (!NNS) |
| 3375 | return QualType(); |
| 3376 | |
| 3377 | TemplateArgumentListInfo NewTemplateArgs; |
| 3378 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 3379 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 3380 | |
| 3381 | for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) { |
| 3382 | TemplateArgumentLoc Loc; |
| 3383 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc)) |
| 3384 | return QualType(); |
| 3385 | NewTemplateArgs.addArgument(Loc); |
| 3386 | } |
| 3387 | |
| 3388 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| 3389 | T->getKeyword(), |
| 3390 | NNS, |
| 3391 | T->getIdentifier(), |
| 3392 | TL.getNameLoc(), |
| 3393 | NewTemplateArgs); |
| 3394 | if (Result.isNull()) |
| 3395 | return QualType(); |
| 3396 | |
| 3397 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 3398 | QualType NamedT = ElabT->getNamedType(); |
| 3399 | |
| 3400 | // Copy information relevant to the template specialization. |
| 3401 | TemplateSpecializationTypeLoc NamedTL |
| 3402 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 3403 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 3404 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 3405 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3406 | NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); |
| 3407 | |
| 3408 | // Copy information relevant to the elaborated type. |
| 3409 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 3410 | NewTL.setKeywordLoc(TL.getKeywordLoc()); |
| 3411 | NewTL.setQualifierRange(TL.getQualifierRange()); |
| 3412 | } else { |
Douglas Gregor | ffa2039 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 3413 | TypeLoc NewTL(Result, TL.getOpaqueData()); |
| 3414 | TLB.pushFullCopy(NewTL); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3415 | } |
| 3416 | return Result; |
| 3417 | } |
| 3418 | |
| 3419 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3420 | QualType |
| 3421 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3422 | ObjCInterfaceTypeLoc TL, |
| 3423 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3424 | // ObjCInterfaceType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3425 | TLB.pushFullCopy(TL); |
| 3426 | return TL.getType(); |
| 3427 | } |
| 3428 | |
| 3429 | template<typename Derived> |
| 3430 | QualType |
| 3431 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 3432 | ObjCObjectTypeLoc TL, |
| 3433 | QualType ObjectType) { |
| 3434 | // ObjCObjectType is never dependent. |
| 3435 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3436 | return TL.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3437 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3438 | |
| 3439 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3440 | QualType |
| 3441 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 3442 | ObjCObjectPointerTypeLoc TL, |
| 3443 | QualType ObjectType) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3444 | // ObjCObjectPointerType is never dependent. |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3445 | TLB.pushFullCopy(TL); |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 3446 | return TL.getType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3449 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | // Statement transformation |
| 3451 | //===----------------------------------------------------------------------===// |
| 3452 | template<typename Derived> |
| 3453 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3455 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | template<typename Derived> |
| 3459 | Sema::OwningStmtResult |
| 3460 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3461 | return getDerived().TransformCompoundStmt(S, false); |
| 3462 | } |
| 3463 | |
| 3464 | template<typename Derived> |
| 3465 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3466 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3467 | bool IsStmtExpr) { |
| 3468 | bool SubStmtChanged = false; |
| 3469 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3470 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3471 | B != BEnd; ++B) { |
| 3472 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3473 | if (Result.isInvalid()) |
| 3474 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3475 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3476 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3477 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3478 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3480 | if (!getDerived().AlwaysRebuild() && |
| 3481 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3483 | |
| 3484 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3485 | move_arg(Statements), |
| 3486 | S->getRBracLoc(), |
| 3487 | IsStmtExpr); |
| 3488 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3490 | template<typename Derived> |
| 3491 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3492 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3493 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3494 | { |
| 3495 | // The case value expressions are not potentially evaluated. |
| 3496 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3497 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3498 | // Transform the left-hand case value. |
| 3499 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3500 | if (LHS.isInvalid()) |
| 3501 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3502 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3503 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3504 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3505 | if (RHS.isInvalid()) |
| 3506 | return SemaRef.StmtError(); |
| 3507 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3508 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3509 | // Build the case statement. |
| 3510 | // Case statements are always rebuilt so that they will attached to their |
| 3511 | // transformed switch statement. |
| 3512 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3513 | move(LHS), |
| 3514 | S->getEllipsisLoc(), |
| 3515 | move(RHS), |
| 3516 | S->getColonLoc()); |
| 3517 | if (Case.isInvalid()) |
| 3518 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3520 | // Transform the statement following the case |
| 3521 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3522 | if (SubStmt.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 | // Attach the body to the case statement |
| 3526 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3527 | } |
| 3528 | |
| 3529 | template<typename Derived> |
| 3530 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3532 | // Transform the statement following the default case |
| 3533 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3534 | if (SubStmt.isInvalid()) |
| 3535 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3537 | // Default statements are always rebuilt |
| 3538 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3539 | move(SubStmt)); |
| 3540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3542 | template<typename Derived> |
| 3543 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3546 | if (SubStmt.isInvalid()) |
| 3547 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3549 | // FIXME: Pass the real colon location in. |
| 3550 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3551 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3552 | move(SubStmt)); |
| 3553 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3554 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3555 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3556 | Sema::OwningStmtResult |
| 3557 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3558 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3559 | OwningExprResult Cond(SemaRef); |
| 3560 | VarDecl *ConditionVar = 0; |
| 3561 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3562 | ConditionVar |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3563 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3564 | getDerived().TransformDefinition( |
| 3565 | S->getConditionVariable()->getLocation(), |
| 3566 | S->getConditionVariable())); |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3567 | if (!ConditionVar) |
| 3568 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3569 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3570 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3571 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3572 | if (Cond.isInvalid()) |
| 3573 | return SemaRef.StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3574 | |
| 3575 | // Convert the condition to a boolean value. |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3576 | if (S->getCond()) { |
| 3577 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3578 | S->getIfLoc(), |
| 3579 | move(Cond)); |
| 3580 | if (CondE.isInvalid()) |
| 3581 | return getSema().StmtError(); |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3582 | |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3583 | Cond = move(CondE); |
| 3584 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3585 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3586 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3587 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3588 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3589 | return SemaRef.StmtError(); |
| 3590 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3591 | // Transform the "then" branch. |
| 3592 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3593 | if (Then.isInvalid()) |
| 3594 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3595 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3596 | // Transform the "else" branch. |
| 3597 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3598 | if (Else.isInvalid()) |
| 3599 | return SemaRef.StmtError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3602 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3603 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3604 | Then.get() == S->getThen() && |
| 3605 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3606 | return SemaRef.Owned(S->Retain()); |
| 3607 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3608 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3609 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | template<typename Derived> |
| 3614 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3616 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3617 | OwningExprResult Cond(SemaRef); |
| 3618 | VarDecl *ConditionVar = 0; |
| 3619 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3620 | ConditionVar |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3621 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3622 | getDerived().TransformDefinition( |
| 3623 | S->getConditionVariable()->getLocation(), |
| 3624 | S->getConditionVariable())); |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3625 | if (!ConditionVar) |
| 3626 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3627 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3628 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3629 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3630 | if (Cond.isInvalid()) |
| 3631 | return SemaRef.StmtError(); |
| 3632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3633 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3634 | // Rebuild the switch statement. |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3635 | OwningStmtResult Switch |
| 3636 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), |
| 3637 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3638 | if (Switch.isInvalid()) |
| 3639 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3641 | // Transform the body of the switch statement. |
| 3642 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3643 | if (Body.isInvalid()) |
| 3644 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3646 | // Complete the switch statement. |
| 3647 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3648 | move(Body)); |
| 3649 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3651 | template<typename Derived> |
| 3652 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3654 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3655 | OwningExprResult Cond(SemaRef); |
| 3656 | VarDecl *ConditionVar = 0; |
| 3657 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3658 | ConditionVar |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3659 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3660 | getDerived().TransformDefinition( |
| 3661 | S->getConditionVariable()->getLocation(), |
| 3662 | S->getConditionVariable())); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3663 | if (!ConditionVar) |
| 3664 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3665 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3666 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3667 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3668 | if (Cond.isInvalid()) |
| 3669 | return SemaRef.StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3670 | |
| 3671 | if (S->getCond()) { |
| 3672 | // Convert the condition to a boolean value. |
| 3673 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3674 | S->getWhileLoc(), |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3675 | move(Cond)); |
| 3676 | if (CondE.isInvalid()) |
| 3677 | return getSema().StmtError(); |
| 3678 | Cond = move(CondE); |
| 3679 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3681 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3682 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3683 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3684 | return SemaRef.StmtError(); |
| 3685 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3686 | // Transform the body |
| 3687 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3688 | if (Body.isInvalid()) |
| 3689 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3691 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3692 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3693 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3694 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3695 | return SemaRef.Owned(S->Retain()); |
| 3696 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3697 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, |
Douglas Gregor | e60e41a | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 3698 | ConditionVar, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3699 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3700 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3701 | template<typename Derived> |
| 3702 | Sema::OwningStmtResult |
| 3703 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3704 | // Transform the body |
| 3705 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3706 | if (Body.isInvalid()) |
| 3707 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3708 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3709 | // Transform the condition |
| 3710 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3711 | if (Cond.isInvalid()) |
| 3712 | return SemaRef.StmtError(); |
| 3713 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3714 | if (!getDerived().AlwaysRebuild() && |
| 3715 | Cond.get() == S->getCond() && |
| 3716 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3717 | return SemaRef.Owned(S->Retain()); |
| 3718 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3719 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3720 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3721 | S->getRParenLoc()); |
| 3722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3723 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3724 | template<typename Derived> |
| 3725 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3727 | // Transform the initialization statement |
| 3728 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3729 | if (Init.isInvalid()) |
| 3730 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3731 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3732 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3733 | OwningExprResult Cond(SemaRef); |
| 3734 | VarDecl *ConditionVar = 0; |
| 3735 | if (S->getConditionVariable()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3736 | ConditionVar |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3737 | = cast_or_null<VarDecl>( |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3738 | getDerived().TransformDefinition( |
| 3739 | S->getConditionVariable()->getLocation(), |
| 3740 | S->getConditionVariable())); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3741 | if (!ConditionVar) |
| 3742 | return SemaRef.StmtError(); |
| 3743 | } else { |
| 3744 | Cond = getDerived().TransformExpr(S->getCond()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3746 | if (Cond.isInvalid()) |
| 3747 | return SemaRef.StmtError(); |
Douglas Gregor | 6d319c6 | 2010-05-08 23:34:38 +0000 | [diff] [blame] | 3748 | |
| 3749 | if (S->getCond()) { |
| 3750 | // Convert the condition to a boolean value. |
| 3751 | OwningExprResult CondE = getSema().ActOnBooleanCondition(0, |
| 3752 | S->getForLoc(), |
| 3753 | move(Cond)); |
| 3754 | if (CondE.isInvalid()) |
| 3755 | return getSema().StmtError(); |
| 3756 | |
| 3757 | Cond = move(CondE); |
| 3758 | } |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3759 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3761 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
| 3762 | if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) |
| 3763 | return SemaRef.StmtError(); |
| 3764 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3765 | // Transform the increment |
| 3766 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3767 | if (Inc.isInvalid()) |
| 3768 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3769 | |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3770 | Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); |
| 3771 | if (S->getInc() && !FullInc->get()) |
| 3772 | return SemaRef.StmtError(); |
| 3773 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3774 | // Transform the body |
| 3775 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3776 | if (Body.isInvalid()) |
| 3777 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3779 | if (!getDerived().AlwaysRebuild() && |
| 3780 | Init.get() == S->getInit() && |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3781 | FullCond->get() == S->getCond() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3782 | Inc.get() == S->getInc() && |
| 3783 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3784 | return SemaRef.Owned(S->Retain()); |
| 3785 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3786 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 3787 | move(Init), FullCond, ConditionVar, |
| 3788 | FullInc, S->getRParenLoc(), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | Sema::OwningStmtResult |
| 3793 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3794 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3796 | S->getLabel()); |
| 3797 | } |
| 3798 | |
| 3799 | template<typename Derived> |
| 3800 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3801 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3802 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3803 | if (Target.isInvalid()) |
| 3804 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3806 | if (!getDerived().AlwaysRebuild() && |
| 3807 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3809 | |
| 3810 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3811 | move(Target)); |
| 3812 | } |
| 3813 | |
| 3814 | template<typename Derived> |
| 3815 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3816 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3817 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3820 | template<typename Derived> |
| 3821 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3823 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3824 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3825 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3826 | template<typename Derived> |
| 3827 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3828 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3829 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3830 | if (Result.isInvalid()) |
| 3831 | return SemaRef.StmtError(); |
| 3832 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3833 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3834 | // to tell whether the return type of the function has changed. |
| 3835 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3836 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3837 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3838 | template<typename Derived> |
| 3839 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3841 | bool DeclChanged = false; |
| 3842 | llvm::SmallVector<Decl *, 4> Decls; |
| 3843 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3844 | D != DEnd; ++D) { |
Douglas Gregor | 2528936 | 2010-03-01 17:25:41 +0000 | [diff] [blame] | 3845 | Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), |
| 3846 | *D); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3847 | if (!Transformed) |
| 3848 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3850 | if (Transformed != *D) |
| 3851 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3853 | Decls.push_back(Transformed); |
| 3854 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3855 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3856 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | return SemaRef.Owned(S->Retain()); |
| 3858 | |
| 3859 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3860 | S->getStartLoc(), S->getEndLoc()); |
| 3861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3862 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3863 | template<typename Derived> |
| 3864 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3865 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3866 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | template<typename Derived> |
| 3871 | Sema::OwningStmtResult |
| 3872 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3873 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3874 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3875 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3876 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3877 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3878 | OwningExprResult AsmString(SemaRef); |
| 3879 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3880 | |
| 3881 | bool ExprsChanged = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3882 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3883 | // Go through the outputs. |
| 3884 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3885 | Names.push_back(S->getOutputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3886 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3887 | // No need to transform the constraint literal. |
| 3888 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3889 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3890 | // Transform the output expr. |
| 3891 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3892 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3893 | if (Result.isInvalid()) |
| 3894 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3895 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3896 | ExprsChanged |= Result.get() != OutputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3897 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3898 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3899 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3900 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3901 | // Go through the inputs. |
| 3902 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3903 | Names.push_back(S->getInputIdentifier(I)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3904 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3905 | // No need to transform the constraint literal. |
| 3906 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3907 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3908 | // Transform the input expr. |
| 3909 | Expr *InputExpr = S->getInputExpr(I); |
| 3910 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3911 | if (Result.isInvalid()) |
| 3912 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3913 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3914 | ExprsChanged |= Result.get() != InputExpr; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3915 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3916 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3917 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3918 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3919 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3920 | return SemaRef.Owned(S->Retain()); |
| 3921 | |
| 3922 | // Go through the clobbers. |
| 3923 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3924 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3925 | |
| 3926 | // No need to transform the asm string literal. |
| 3927 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3928 | |
| 3929 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3930 | S->isSimple(), |
| 3931 | S->isVolatile(), |
| 3932 | S->getNumOutputs(), |
| 3933 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3934 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3935 | move_arg(Constraints), |
| 3936 | move_arg(Exprs), |
| 3937 | move(AsmString), |
| 3938 | move_arg(Clobbers), |
| 3939 | S->getRParenLoc(), |
| 3940 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | |
| 3944 | template<typename Derived> |
| 3945 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3946 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3947 | // Transform the body of the @try. |
| 3948 | OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 3949 | if (TryBody.isInvalid()) |
| 3950 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3951 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3952 | // Transform the @catch statements (if present). |
| 3953 | bool AnyCatchChanged = false; |
| 3954 | ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef); |
| 3955 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 3956 | OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3957 | if (Catch.isInvalid()) |
| 3958 | return SemaRef.StmtError(); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3959 | if (Catch.get() != S->getCatchStmt(I)) |
| 3960 | AnyCatchChanged = true; |
| 3961 | CatchStmts.push_back(Catch.release()); |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3962 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3963 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3964 | // Transform the @finally statement (if present). |
| 3965 | OwningStmtResult Finally(SemaRef); |
| 3966 | if (S->getFinallyStmt()) { |
| 3967 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 3968 | if (Finally.isInvalid()) |
| 3969 | return SemaRef.StmtError(); |
| 3970 | } |
| 3971 | |
| 3972 | // If nothing changed, just retain this statement. |
| 3973 | if (!getDerived().AlwaysRebuild() && |
| 3974 | TryBody.get() == S->getTryBody() && |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3975 | !AnyCatchChanged && |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3976 | Finally.get() == S->getFinallyStmt()) |
| 3977 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 3979 | // Build a new statement. |
| 3980 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 3981 | move_arg(CatchStmts), move(Finally)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3984 | template<typename Derived> |
| 3985 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3987 | // Transform the @catch parameter, if there is one. |
| 3988 | VarDecl *Var = 0; |
| 3989 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 3990 | TypeSourceInfo *TSInfo = 0; |
| 3991 | if (FromVar->getTypeSourceInfo()) { |
| 3992 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 3993 | if (!TSInfo) |
| 3994 | return SemaRef.StmtError(); |
| 3995 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 3996 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 3997 | QualType T; |
| 3998 | if (TSInfo) |
| 3999 | T = TSInfo->getType(); |
| 4000 | else { |
| 4001 | T = getDerived().TransformType(FromVar->getType()); |
| 4002 | if (T.isNull()) |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4003 | return SemaRef.StmtError(); |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4004 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4006 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 4007 | if (!Var) |
| 4008 | return SemaRef.StmtError(); |
| 4009 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4010 | |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4011 | OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 4012 | if (Body.isInvalid()) |
| 4013 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4014 | |
| 4015 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 4016 | S->getRParenLoc(), |
| 4017 | Var, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4018 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4020 | template<typename Derived> |
| 4021 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4023 | // Transform the body. |
| 4024 | OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 4025 | if (Body.isInvalid()) |
| 4026 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 4028 | // If nothing changed, just retain this statement. |
| 4029 | if (!getDerived().AlwaysRebuild() && |
| 4030 | Body.get() == S->getFinallyBody()) |
| 4031 | return SemaRef.Owned(S->Retain()); |
| 4032 | |
| 4033 | // Build a new statement. |
| 4034 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 4035 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4036 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4037 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4038 | template<typename Derived> |
| 4039 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4041 | OwningExprResult Operand(SemaRef); |
| 4042 | if (S->getThrowExpr()) { |
| 4043 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 4044 | if (Operand.isInvalid()) |
| 4045 | return getSema().StmtError(); |
| 4046 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4047 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4048 | if (!getDerived().AlwaysRebuild() && |
| 4049 | Operand.get() == S->getThrowExpr()) |
| 4050 | return getSema().Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 4052 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4055 | template<typename Derived> |
| 4056 | Sema::OwningStmtResult |
| 4057 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4059 | // Transform the object we are locking. |
| 4060 | OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 4061 | if (Object.isInvalid()) |
| 4062 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4064 | // Transform the body. |
| 4065 | OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 4066 | if (Body.isInvalid()) |
| 4067 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 4069 | // If nothing change, just retain the current statement. |
| 4070 | if (!getDerived().AlwaysRebuild() && |
| 4071 | Object.get() == S->getSynchExpr() && |
| 4072 | Body.get() == S->getSynchBody()) |
| 4073 | return SemaRef.Owned(S->Retain()); |
| 4074 | |
| 4075 | // Build a new statement. |
| 4076 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 4077 | move(Object), move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | template<typename Derived> |
| 4081 | Sema::OwningStmtResult |
| 4082 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | ObjCForCollectionStmt *S) { |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4084 | // Transform the element statement. |
| 4085 | OwningStmtResult Element = getDerived().TransformStmt(S->getElement()); |
| 4086 | if (Element.isInvalid()) |
| 4087 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4088 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4089 | // Transform the collection expression. |
| 4090 | OwningExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 4091 | if (Collection.isInvalid()) |
| 4092 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4093 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4094 | // Transform the body. |
| 4095 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 4096 | if (Body.isInvalid()) |
| 4097 | return SemaRef.StmtError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4098 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4099 | // If nothing changed, just retain this statement. |
| 4100 | if (!getDerived().AlwaysRebuild() && |
| 4101 | Element.get() == S->getElement() && |
| 4102 | Collection.get() == S->getCollection() && |
| 4103 | Body.get() == S->getBody()) |
| 4104 | return SemaRef.Owned(S->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 4106 | // Build a new statement. |
| 4107 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 4108 | /*FIXME:*/S->getForLoc(), |
| 4109 | move(Element), |
| 4110 | move(Collection), |
| 4111 | S->getRParenLoc(), |
| 4112 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | |
| 4116 | template<typename Derived> |
| 4117 | Sema::OwningStmtResult |
| 4118 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 4119 | // Transform the exception declaration, if any. |
| 4120 | VarDecl *Var = 0; |
| 4121 | if (S->getExceptionDecl()) { |
| 4122 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 4123 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 4124 | ExceptionDecl->getDeclName()); |
| 4125 | |
| 4126 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 4127 | if (T.isNull()) |
| 4128 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4130 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 4131 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4132 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4133 | ExceptionDecl->getIdentifier(), |
| 4134 | ExceptionDecl->getLocation(), |
| 4135 | /*FIXME: Inaccurate*/ |
| 4136 | SourceRange(ExceptionDecl->getLocation())); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 4137 | if (!Var || Var->isInvalidDecl()) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4138 | return SemaRef.StmtError(); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4141 | // Transform the actual exception handler. |
| 4142 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 4143 | if (Handler.isInvalid()) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4144 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4146 | if (!getDerived().AlwaysRebuild() && |
| 4147 | !Var && |
| 4148 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4150 | |
| 4151 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 4152 | Var, |
| 4153 | move(Handler)); |
| 4154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4155 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4156 | template<typename Derived> |
| 4157 | Sema::OwningStmtResult |
| 4158 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 4159 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4161 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 4162 | if (TryBlock.isInvalid()) |
| 4163 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4164 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4165 | // Transform the handlers. |
| 4166 | bool HandlerChanged = false; |
| 4167 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 4168 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4169 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4170 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 4171 | if (Handler.isInvalid()) |
| 4172 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4174 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 4175 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 4176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4178 | if (!getDerived().AlwaysRebuild() && |
| 4179 | TryBlock.get() == S->getTryBlock() && |
| 4180 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4182 | |
| 4183 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4185 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4186 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4187 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | // Expression transformation |
| 4189 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4190 | template<typename Derived> |
| 4191 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4192 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | |
| 4196 | template<typename Derived> |
| 4197 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4198 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4199 | NestedNameSpecifier *Qualifier = 0; |
| 4200 | if (E->getQualifier()) { |
| 4201 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4202 | E->getQualifierRange()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4203 | if (!Qualifier) |
| 4204 | return SemaRef.ExprError(); |
| 4205 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4206 | |
| 4207 | ValueDecl *ND |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4208 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 4209 | E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | if (!ND) |
| 4211 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | |
John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 4213 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 4214 | if (NameInfo.getName()) { |
| 4215 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 4216 | if (!NameInfo.getName()) |
| 4217 | return SemaRef.ExprError(); |
| 4218 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4219 | |
| 4220 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4221 | Qualifier == E->getQualifier() && |
| 4222 | ND == E->getDecl() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4223 | NameInfo.getName() == E->getDecl()->getDeclName() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 4224 | !E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4225 | |
| 4226 | // Mark it referenced in the new context regardless. |
| 4227 | // FIXME: this is a bit instantiation-specific. |
| 4228 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 4229 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4231 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4232 | |
| 4233 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 4234 | if (E->hasExplicitTemplateArgs()) { |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 4235 | TemplateArgs = &TransArgs; |
| 4236 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4237 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 4238 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 4239 | TemplateArgumentLoc Loc; |
| 4240 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 4241 | return SemaRef.ExprError(); |
| 4242 | TransArgs.addArgument(Loc); |
| 4243 | } |
| 4244 | } |
| 4245 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 4246 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4247 | ND, NameInfo, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4250 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4251 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4252 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4256 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4258 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4264 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4265 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4267 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4268 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4269 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4270 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4271 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4272 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4273 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4274 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4276 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4277 | return SemaRef.Owned(E->Retain()); |
| 4278 | } |
| 4279 | |
| 4280 | template<typename Derived> |
| 4281 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4282 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4283 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4284 | if (SubExpr.isInvalid()) |
| 4285 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4286 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4287 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | return SemaRef.Owned(E->Retain()); |
| 4289 | |
| 4290 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4291 | E->getRParen()); |
| 4292 | } |
| 4293 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4294 | template<typename Derived> |
| 4295 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4296 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 4297 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4298 | if (SubExpr.isInvalid()) |
| 4299 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4300 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4302 | return SemaRef.Owned(E->Retain()); |
| 4303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 4305 | E->getOpcode(), |
| 4306 | move(SubExpr)); |
| 4307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4309 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4310 | Sema::OwningExprResult |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4311 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 4312 | // Transform the type. |
| 4313 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 4314 | if (!Type) |
| 4315 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4316 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4317 | // Transform all of the components into components similar to what the |
| 4318 | // parser uses. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4319 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 4320 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 4321 | // the fields again. However, __builtin_offsetof is rare enough in |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4322 | // template code that we don't care. |
| 4323 | bool ExprChanged = false; |
| 4324 | typedef Action::OffsetOfComponent Component; |
| 4325 | typedef OffsetOfExpr::OffsetOfNode Node; |
| 4326 | llvm::SmallVector<Component, 4> Components; |
| 4327 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 4328 | const Node &ON = E->getComponent(I); |
| 4329 | Component Comp; |
Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 4330 | Comp.isBrackets = true; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4331 | Comp.LocStart = ON.getRange().getBegin(); |
| 4332 | Comp.LocEnd = ON.getRange().getEnd(); |
| 4333 | switch (ON.getKind()) { |
| 4334 | case Node::Array: { |
| 4335 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 4336 | OwningExprResult Index = getDerived().TransformExpr(FromIndex); |
| 4337 | if (Index.isInvalid()) |
| 4338 | return getSema().ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4339 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4340 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 4341 | Comp.isBrackets = true; |
| 4342 | Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked |
| 4343 | break; |
| 4344 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4345 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4346 | case Node::Field: |
| 4347 | case Node::Identifier: |
| 4348 | Comp.isBrackets = false; |
| 4349 | Comp.U.IdentInfo = ON.getFieldName(); |
Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 4350 | if (!Comp.U.IdentInfo) |
| 4351 | continue; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4352 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4353 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 4355 | case Node::Base: |
| 4356 | // Will be recomputed during the rebuild. |
| 4357 | continue; |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4358 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4359 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4360 | Components.push_back(Comp); |
| 4361 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4362 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4363 | // If nothing changed, retain the existing expression. |
| 4364 | if (!getDerived().AlwaysRebuild() && |
| 4365 | Type == E->getTypeSourceInfo() && |
| 4366 | !ExprChanged) |
| 4367 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4368 | |
Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 4369 | // Build a new offsetof expression. |
| 4370 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 4371 | Components.data(), Components.size(), |
| 4372 | E->getRParenLoc()); |
| 4373 | } |
| 4374 | |
| 4375 | template<typename Derived> |
| 4376 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4377 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4378 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4379 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4380 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4381 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4382 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4383 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4384 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4385 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 4388 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | E->getSourceRange()); |
| 4391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4393 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4395 | // C++0x [expr.sizeof]p1: |
| 4396 | // The operand is either an expression, which is an unevaluated operand |
| 4397 | // [...] |
| 4398 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 4401 | if (SubExpr.isInvalid()) |
| 4402 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 4405 | return SemaRef.Owned(E->Retain()); |
| 4406 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 4409 | E->isSizeOf(), |
| 4410 | E->getSourceRange()); |
| 4411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4415 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4416 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4417 | if (LHS.isInvalid()) |
| 4418 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4419 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4420 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4421 | if (RHS.isInvalid()) |
| 4422 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4423 | |
| 4424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | if (!getDerived().AlwaysRebuild() && |
| 4426 | LHS.get() == E->getLHS() && |
| 4427 | RHS.get() == E->getRHS()) |
| 4428 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4429 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4430 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 4431 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 4432 | move(RHS), |
| 4433 | E->getRBracketLoc()); |
| 4434 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | |
| 4436 | template<typename Derived> |
| 4437 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4438 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4439 | // Transform the callee. |
| 4440 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4441 | if (Callee.isInvalid()) |
| 4442 | return SemaRef.ExprError(); |
| 4443 | |
| 4444 | // Transform arguments. |
| 4445 | bool ArgChanged = false; |
| 4446 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4447 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4448 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 4449 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4450 | if (Arg.isInvalid()) |
| 4451 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4453 | // FIXME: Wrong source location information for the ','. |
| 4454 | FakeCommaLocs.push_back( |
| 4455 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | |
| 4457 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4458 | Args.push_back(Arg.takeAs<Expr>()); |
| 4459 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4461 | if (!getDerived().AlwaysRebuild() && |
| 4462 | Callee.get() == E->getCallee() && |
| 4463 | !ArgChanged) |
| 4464 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4465 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4466 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 4469 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 4470 | move_arg(Args), |
| 4471 | FakeCommaLocs.data(), |
| 4472 | E->getRParenLoc()); |
| 4473 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | |
| 4475 | template<typename Derived> |
| 4476 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4477 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4478 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4479 | if (Base.isInvalid()) |
| 4480 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4481 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4482 | NestedNameSpecifier *Qualifier = 0; |
| 4483 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4485 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 4486 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 4487 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4488 | return SemaRef.ExprError(); |
| 4489 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 4491 | ValueDecl *Member |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 4492 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 4493 | E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4494 | if (!Member) |
| 4495 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4497 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 4498 | if (FoundDecl == E->getMemberDecl()) { |
| 4499 | FoundDecl = Member; |
| 4500 | } else { |
| 4501 | FoundDecl = cast_or_null<NamedDecl>( |
| 4502 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 4503 | if (!FoundDecl) |
| 4504 | return SemaRef.ExprError(); |
| 4505 | } |
| 4506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | if (!getDerived().AlwaysRebuild() && |
| 4508 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4509 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4510 | Member == E->getMemberDecl() && |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4511 | FoundDecl == E->getFoundDecl() && |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 4512 | !E->hasExplicitTemplateArgs()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4513 | |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4514 | // Mark it referenced in the new context regardless. |
| 4515 | // FIXME: this is a bit instantiation-specific. |
| 4516 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4517 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 4518 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4519 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4520 | TemplateArgumentListInfo TransArgs; |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 4521 | if (E->hasExplicitTemplateArgs()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4522 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 4523 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4524 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4525 | TemplateArgumentLoc Loc; |
| 4526 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4527 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4528 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4529 | } |
| 4530 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4531 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | // FIXME: Bogus source location for the operator |
| 4533 | SourceLocation FakeOperatorLoc |
| 4534 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 4535 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4536 | // FIXME: to do this check properly, we will need to preserve the |
| 4537 | // first-qualifier-in-scope here, just in case we had a dependent |
| 4538 | // base (and therefore couldn't do the check) and a |
| 4539 | // nested-name-qualifier (and therefore could do the lookup). |
| 4540 | NamedDecl *FirstQualifierInScope = 0; |
| 4541 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4542 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 4543 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 4544 | Qualifier, |
| 4545 | E->getQualifierRange(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 4546 | E->getMemberNameInfo(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 4547 | Member, |
John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 4548 | FoundDecl, |
John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 4549 | (E->hasExplicitTemplateArgs() |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4550 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 4551 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4552 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4553 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4554 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4556 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4558 | if (LHS.isInvalid()) |
| 4559 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4562 | if (RHS.isInvalid()) |
| 4563 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | if (!getDerived().AlwaysRebuild() && |
| 4566 | LHS.get() == E->getLHS() && |
| 4567 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4568 | return SemaRef.Owned(E->Retain()); |
| 4569 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 4571 | move(LHS), move(RHS)); |
| 4572 | } |
| 4573 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | Sema::OwningExprResult |
| 4576 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4577 | CompoundAssignOperator *E) { |
| 4578 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4581 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4582 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4583 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4585 | if (Cond.isInvalid()) |
| 4586 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4588 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4589 | if (LHS.isInvalid()) |
| 4590 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4591 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4592 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4593 | if (RHS.isInvalid()) |
| 4594 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4596 | if (!getDerived().AlwaysRebuild() && |
| 4597 | Cond.get() == E->getCond() && |
| 4598 | LHS.get() == E->getLHS() && |
| 4599 | RHS.get() == E->getRHS()) |
| 4600 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
| 4602 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4603 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4604 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 4605 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4606 | move(RHS)); |
| 4607 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4608 | |
| 4609 | template<typename Derived> |
| 4610 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4611 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4612 | // Implicit casts are eliminated during transformation, since they |
| 4613 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4614 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | template<typename Derived> |
| 4618 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4619 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4620 | TypeSourceInfo *OldT; |
| 4621 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4622 | { |
| 4623 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4624 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 4626 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4627 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4628 | OldT = E->getTypeInfoAsWritten(); |
| 4629 | NewT = getDerived().TransformType(OldT); |
| 4630 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4631 | return SemaRef.ExprError(); |
| 4632 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4633 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4634 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4635 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4636 | if (SubExpr.isInvalid()) |
| 4637 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4638 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4639 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4640 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4642 | return SemaRef.Owned(E->Retain()); |
| 4643 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4644 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 4645 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | E->getRParenLoc(), |
| 4647 | move(SubExpr)); |
| 4648 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4650 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4651 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4652 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4653 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 4654 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 4655 | if (!NewT) |
| 4656 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 4659 | if (Init.isInvalid()) |
| 4660 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4662 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4663 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4664 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 4667 | // Note: the expression type doesn't necessarily match the |
| 4668 | // type-as-written, but that's okay, because it should always be |
| 4669 | // derivable from the initializer. |
| 4670 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 4671 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4672 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 4673 | move(Init)); |
| 4674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4676 | template<typename Derived> |
| 4677 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4678 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4679 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4680 | if (Base.isInvalid()) |
| 4681 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4682 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4683 | if (!getDerived().AlwaysRebuild() && |
| 4684 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4685 | return SemaRef.Owned(E->Retain()); |
| 4686 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4687 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4690 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4691 | E->getAccessorLoc(), |
| 4692 | E->getAccessor()); |
| 4693 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4694 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4695 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4697 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4698 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4699 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4701 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4702 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4703 | if (Init.isInvalid()) |
| 4704 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4706 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4707 | Inits.push_back(Init.takeAs<Expr>()); |
| 4708 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4710 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4711 | return SemaRef.Owned(E->Retain()); |
| 4712 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4714 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4715 | } |
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 | template<typename Derived> |
| 4718 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4719 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4720 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4722 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4724 | if (Init.isInvalid()) |
| 4725 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4726 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4727 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4728 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4729 | bool ExprChanged = false; |
| 4730 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4731 | DEnd = E->designators_end(); |
| 4732 | D != DEnd; ++D) { |
| 4733 | if (D->isFieldDesignator()) { |
| 4734 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4735 | D->getDotLoc(), |
| 4736 | D->getFieldLoc())); |
| 4737 | continue; |
| 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 | if (D->isArrayDesignator()) { |
| 4741 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4742 | if (Index.isInvalid()) |
| 4743 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4744 | |
| 4745 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4746 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4749 | ArrayExprs.push_back(Index.release()); |
| 4750 | continue; |
| 4751 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4752 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4753 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4756 | if (Start.isInvalid()) |
| 4757 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4759 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4760 | if (End.isInvalid()) |
| 4761 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4762 | |
| 4763 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | End.get(), |
| 4765 | D->getLBracketLoc(), |
| 4766 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4768 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4769 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4771 | ArrayExprs.push_back(Start.release()); |
| 4772 | ArrayExprs.push_back(End.release()); |
| 4773 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4775 | if (!getDerived().AlwaysRebuild() && |
| 4776 | Init.get() == E->getInit() && |
| 4777 | !ExprChanged) |
| 4778 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4781 | E->getEqualOrColonLoc(), |
| 4782 | E->usesGNUSyntax(), move(Init)); |
| 4783 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4784 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4785 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4786 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4788 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4789 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4790 | |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4791 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4792 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4793 | QualType T = getDerived().TransformType(E->getType()); |
| 4794 | if (T.isNull()) |
| 4795 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4797 | if (!getDerived().AlwaysRebuild() && |
| 4798 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4799 | return SemaRef.Owned(E->Retain()); |
| 4800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4802 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4803 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4804 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4805 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4806 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 4807 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 4808 | if (!TInfo) |
| 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 SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4812 | if (SubExpr.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() && |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 4816 | TInfo == E->getWrittenTypeInfo() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | SubExpr.get() == E->getSubExpr()) |
| 4818 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4819 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4820 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 4821 | TInfo, E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4825 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4826 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4827 | bool ArgumentChanged = false; |
| 4828 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4829 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4830 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4831 | if (Init.isInvalid()) |
| 4832 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4835 | Inits.push_back(Init.takeAs<Expr>()); |
| 4836 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4839 | move_arg(Inits), |
| 4840 | E->getRParenLoc()); |
| 4841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4843 | /// \brief Transform an address-of-label expression. |
| 4844 | /// |
| 4845 | /// By default, the transformation of an address-of-label expression always |
| 4846 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4847 | /// the corresponding label statement by semantic analysis. |
| 4848 | template<typename Derived> |
| 4849 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4850 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4851 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4852 | E->getLabel()); |
| 4853 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | |
| 4855 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4856 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4857 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4859 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4860 | if (SubStmt.isInvalid()) |
| 4861 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4862 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4863 | if (!getDerived().AlwaysRebuild() && |
| 4864 | SubStmt.get() == E->getSubStmt()) |
| 4865 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4866 | |
| 4867 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4868 | move(SubStmt), |
| 4869 | E->getRParenLoc()); |
| 4870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4871 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4872 | template<typename Derived> |
| 4873 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4874 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4875 | TypeSourceInfo *TInfo1; |
| 4876 | TypeSourceInfo *TInfo2; |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 4877 | |
| 4878 | TInfo1 = getDerived().TransformType(E->getArgTInfo1()); |
| 4879 | if (!TInfo1) |
| 4880 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4881 | |
Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 4882 | TInfo2 = getDerived().TransformType(E->getArgTInfo2()); |
| 4883 | if (!TInfo2) |
| 4884 | return SemaRef.ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4885 | |
| 4886 | if (!getDerived().AlwaysRebuild() && |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4887 | TInfo1 == E->getArgTInfo1() && |
| 4888 | TInfo2 == E->getArgTInfo2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4889 | return SemaRef.Owned(E->Retain()); |
| 4890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4891 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
Abramo Bagnara | 092990a | 2010-08-10 08:50:03 +0000 | [diff] [blame] | 4892 | TInfo1, TInfo2, |
| 4893 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4895 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4896 | template<typename Derived> |
| 4897 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4898 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4899 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4900 | if (Cond.isInvalid()) |
| 4901 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4902 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4903 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4904 | if (LHS.isInvalid()) |
| 4905 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4906 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4907 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4908 | if (RHS.isInvalid()) |
| 4909 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4911 | if (!getDerived().AlwaysRebuild() && |
| 4912 | Cond.get() == E->getCond() && |
| 4913 | LHS.get() == E->getLHS() && |
| 4914 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4915 | return SemaRef.Owned(E->Retain()); |
| 4916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4917 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4918 | move(Cond), move(LHS), move(RHS), |
| 4919 | E->getRParenLoc()); |
| 4920 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4921 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4922 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4923 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4924 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4925 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | template<typename Derived> |
| 4929 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4930 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4931 | switch (E->getOperator()) { |
| 4932 | case OO_New: |
| 4933 | case OO_Delete: |
| 4934 | case OO_Array_New: |
| 4935 | case OO_Array_Delete: |
| 4936 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4937 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4938 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4939 | case OO_Call: { |
| 4940 | // This is a call to an object's operator(). |
| 4941 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4942 | |
| 4943 | // Transform the object itself. |
| 4944 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4945 | if (Object.isInvalid()) |
| 4946 | return SemaRef.ExprError(); |
| 4947 | |
| 4948 | // FIXME: Poor location information |
| 4949 | SourceLocation FakeLParenLoc |
| 4950 | = SemaRef.PP.getLocForEndOfToken( |
| 4951 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4952 | |
| 4953 | // Transform the call arguments. |
| 4954 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4955 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4956 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4957 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4958 | break; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 4959 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4960 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4961 | if (Arg.isInvalid()) |
| 4962 | return SemaRef.ExprError(); |
| 4963 | |
| 4964 | // FIXME: Poor source location information. |
| 4965 | SourceLocation FakeCommaLoc |
| 4966 | = SemaRef.PP.getLocForEndOfToken( |
| 4967 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4968 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4969 | Args.push_back(Arg.release()); |
| 4970 | } |
| 4971 | |
| 4972 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4973 | move_arg(Args), |
| 4974 | FakeCommaLocs.data(), |
| 4975 | E->getLocEnd()); |
| 4976 | } |
| 4977 | |
| 4978 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4979 | case OO_##Name: |
| 4980 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4981 | #include "clang/Basic/OperatorKinds.def" |
| 4982 | case OO_Subscript: |
| 4983 | // Handled below. |
| 4984 | break; |
| 4985 | |
| 4986 | case OO_Conditional: |
| 4987 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4988 | return SemaRef.ExprError(); |
| 4989 | |
| 4990 | case OO_None: |
| 4991 | case NUM_OVERLOADED_OPERATORS: |
| 4992 | llvm_unreachable("not an overloaded operator?"); |
| 4993 | return SemaRef.ExprError(); |
| 4994 | } |
| 4995 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4996 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4997 | if (Callee.isInvalid()) |
| 4998 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4999 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5000 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5001 | if (First.isInvalid()) |
| 5002 | return SemaRef.ExprError(); |
| 5003 | |
| 5004 | OwningExprResult Second(SemaRef); |
| 5005 | if (E->getNumArgs() == 2) { |
| 5006 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 5007 | if (Second.isInvalid()) |
| 5008 | return SemaRef.ExprError(); |
| 5009 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5011 | if (!getDerived().AlwaysRebuild() && |
| 5012 | Callee.get() == E->getCallee() && |
| 5013 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5014 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 5015 | return SemaRef.Owned(E->Retain()); |
| 5016 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5017 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 5018 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5020 | move(First), |
| 5021 | move(Second)); |
| 5022 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | template<typename Derived> |
| 5025 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5026 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 5027 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5029 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5030 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5031 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5032 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5033 | TypeSourceInfo *OldT; |
| 5034 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5035 | { |
| 5036 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5037 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5038 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5039 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5040 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5041 | OldT = E->getTypeInfoAsWritten(); |
| 5042 | NewT = getDerived().TransformType(OldT); |
| 5043 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5044 | return SemaRef.ExprError(); |
| 5045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5047 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5048 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5049 | if (SubExpr.isInvalid()) |
| 5050 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5052 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5053 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5054 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | return SemaRef.Owned(E->Retain()); |
| 5056 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5057 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5058 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5059 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 5060 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 5061 | SourceLocation FakeRParenLoc |
| 5062 | = SemaRef.PP.getLocForEndOfToken( |
| 5063 | E->getSubExpr()->getSourceRange().getEnd()); |
| 5064 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5065 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5066 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5067 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5068 | FakeRAngleLoc, |
| 5069 | FakeRAngleLoc, |
| 5070 | move(SubExpr), |
| 5071 | FakeRParenLoc); |
| 5072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5074 | template<typename Derived> |
| 5075 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5076 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 5077 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | |
| 5080 | template<typename Derived> |
| 5081 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5082 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 5083 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | } |
| 5085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5086 | template<typename Derived> |
| 5087 | Sema::OwningExprResult |
| 5088 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5089 | CXXReinterpretCastExpr *E) { |
| 5090 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5091 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5092 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5093 | template<typename Derived> |
| 5094 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5095 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 5096 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5099 | template<typename Derived> |
| 5100 | Sema::OwningExprResult |
| 5101 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5102 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5103 | TypeSourceInfo *OldT; |
| 5104 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5105 | { |
| 5106 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5107 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5108 | OldT = E->getTypeInfoAsWritten(); |
| 5109 | NewT = getDerived().TransformType(OldT); |
| 5110 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5111 | return SemaRef.ExprError(); |
| 5112 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5113 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 5114 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5115 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5116 | if (SubExpr.isInvalid()) |
| 5117 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5120 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5122 | return SemaRef.Owned(E->Retain()); |
| 5123 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5124 | // FIXME: The end of the type's source range is wrong |
| 5125 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 5126 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 5127 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5128 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 5129 | move(SubExpr), |
| 5130 | E->getRParenLoc()); |
| 5131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5133 | template<typename Derived> |
| 5134 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5135 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5136 | if (E->isTypeOperand()) { |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5137 | TypeSourceInfo *TInfo |
| 5138 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 5139 | if (!TInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5140 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5142 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5143 | TInfo == E->getTypeOperandSourceInfo()) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5145 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5146 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5147 | E->getLocStart(), |
| 5148 | TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5149 | E->getLocEnd()); |
| 5150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5151 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5152 | // We don't know whether the expression is potentially evaluated until |
| 5153 | // after we perform semantic analysis, so the expression is potentially |
| 5154 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5155 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5156 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5158 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 5159 | if (SubExpr.isInvalid()) |
| 5160 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5162 | if (!getDerived().AlwaysRebuild() && |
| 5163 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5164 | return SemaRef.Owned(E->Retain()); |
| 5165 | |
Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 5166 | return getDerived().RebuildCXXTypeidExpr(E->getType(), |
| 5167 | E->getLocStart(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | move(SubExpr), |
| 5169 | E->getLocEnd()); |
| 5170 | } |
| 5171 | |
| 5172 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5173 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5174 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5175 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5178 | template<typename Derived> |
| 5179 | Sema::OwningExprResult |
| 5180 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5181 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5184 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5185 | template<typename Derived> |
| 5186 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5187 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5190 | QualType T = getDerived().TransformType(E->getType()); |
| 5191 | if (T.isNull()) |
| 5192 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5194 | if (!getDerived().AlwaysRebuild() && |
| 5195 | T == E->getType()) |
| 5196 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 5198 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5201 | template<typename Derived> |
| 5202 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5203 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 5205 | if (SubExpr.isInvalid()) |
| 5206 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5207 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5208 | if (!getDerived().AlwaysRebuild() && |
| 5209 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5211 | |
| 5212 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 5213 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5215 | template<typename Derived> |
| 5216 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5217 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | ParmVarDecl *Param |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5219 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), |
| 5220 | E->getParam())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5221 | if (!Param) |
| 5222 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 5224 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5225 | Param == E->getParam()) |
| 5226 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 5228 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | template<typename Derived> |
| 5232 | Sema::OwningExprResult |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 5233 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5234 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5235 | |
| 5236 | QualType T = getDerived().TransformType(E->getType()); |
| 5237 | if (T.isNull()) |
| 5238 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5239 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5240 | if (!getDerived().AlwaysRebuild() && |
| 5241 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5242 | return SemaRef.Owned(E->Retain()); |
| 5243 | |
Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 5244 | return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(), |
| 5245 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5246 | T, |
| 5247 | E->getRParenLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | template<typename Derived> |
| 5251 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5252 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5253 | // Transform the type that we're allocating |
| 5254 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 5255 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 5256 | if (AllocType.isNull()) |
| 5257 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5259 | // Transform the size of the array we're allocating (if any). |
| 5260 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 5261 | if (ArraySize.isInvalid()) |
| 5262 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5264 | // Transform the placement arguments (if any). |
| 5265 | bool ArgumentChanged = false; |
| 5266 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 5267 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 5268 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 5269 | if (Arg.isInvalid()) |
| 5270 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5272 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 5273 | PlacementArgs.push_back(Arg.take()); |
| 5274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5275 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 5276 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5277 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 5278 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
Douglas Gregor | 1b30b3c | 2010-05-26 07:10:06 +0000 | [diff] [blame] | 5279 | if (getDerived().DropCallArgument(E->getConstructorArg(I))) |
| 5280 | break; |
| 5281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5282 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 5283 | if (Arg.isInvalid()) |
| 5284 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5285 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5286 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 5287 | ConstructorArgs.push_back(Arg.take()); |
| 5288 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5290 | // Transform constructor, new operator, and delete operator. |
| 5291 | CXXConstructorDecl *Constructor = 0; |
| 5292 | if (E->getConstructor()) { |
| 5293 | Constructor = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5294 | getDerived().TransformDecl(E->getLocStart(), |
| 5295 | E->getConstructor())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5296 | if (!Constructor) |
| 5297 | return SemaRef.ExprError(); |
| 5298 | } |
| 5299 | |
| 5300 | FunctionDecl *OperatorNew = 0; |
| 5301 | if (E->getOperatorNew()) { |
| 5302 | OperatorNew = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5303 | getDerived().TransformDecl(E->getLocStart(), |
| 5304 | E->getOperatorNew())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5305 | if (!OperatorNew) |
| 5306 | return SemaRef.ExprError(); |
| 5307 | } |
| 5308 | |
| 5309 | FunctionDecl *OperatorDelete = 0; |
| 5310 | if (E->getOperatorDelete()) { |
| 5311 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5312 | getDerived().TransformDecl(E->getLocStart(), |
| 5313 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5314 | if (!OperatorDelete) |
| 5315 | return SemaRef.ExprError(); |
| 5316 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5317 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5318 | if (!getDerived().AlwaysRebuild() && |
| 5319 | AllocType == E->getAllocatedType() && |
| 5320 | ArraySize.get() == E->getArraySize() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5321 | Constructor == E->getConstructor() && |
| 5322 | OperatorNew == E->getOperatorNew() && |
| 5323 | OperatorDelete == E->getOperatorDelete() && |
| 5324 | !ArgumentChanged) { |
| 5325 | // Mark any declarations we need as referenced. |
| 5326 | // FIXME: instantiation-specific. |
| 5327 | if (Constructor) |
| 5328 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
| 5329 | if (OperatorNew) |
| 5330 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); |
| 5331 | if (OperatorDelete) |
| 5332 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5333 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5334 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5336 | if (!ArraySize.get()) { |
| 5337 | // If no array size was specified, but the new expression was |
| 5338 | // instantiated with an array type (e.g., "new T" where T is |
| 5339 | // instantiated with "int[4]"), extract the outer bound from the |
| 5340 | // array type as our array size. We do this with constant and |
| 5341 | // dependently-sized array types. |
| 5342 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 5343 | if (!ArrayT) { |
| 5344 | // Do nothing |
| 5345 | } else if (const ConstantArrayType *ConsArrayT |
| 5346 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5347 | ArraySize |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5348 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5349 | ConsArrayT->getSize(), |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 5350 | SemaRef.Context.getSizeType(), |
| 5351 | /*FIXME:*/E->getLocStart())); |
| 5352 | AllocType = ConsArrayT->getElementType(); |
| 5353 | } else if (const DependentSizedArrayType *DepArrayT |
| 5354 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 5355 | if (DepArrayT->getSizeExpr()) { |
| 5356 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 5357 | AllocType = DepArrayT->getElementType(); |
| 5358 | } |
| 5359 | } |
| 5360 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5361 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 5362 | E->isGlobalNew(), |
| 5363 | /*FIXME:*/E->getLocStart(), |
| 5364 | move_arg(PlacementArgs), |
| 5365 | /*FIXME:*/E->getLocStart(), |
Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 5366 | E->getTypeIdParens(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5367 | AllocType, |
| 5368 | /*FIXME:*/E->getLocStart(), |
| 5369 | /*FIXME:*/SourceRange(), |
| 5370 | move(ArraySize), |
| 5371 | /*FIXME:*/E->getLocStart(), |
| 5372 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5373 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5374 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5375 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5376 | template<typename Derived> |
| 5377 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5378 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5379 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 5380 | if (Operand.isInvalid()) |
| 5381 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5382 | |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5383 | // Transform the delete operator, if known. |
| 5384 | FunctionDecl *OperatorDelete = 0; |
| 5385 | if (E->getOperatorDelete()) { |
| 5386 | OperatorDelete = cast_or_null<FunctionDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5387 | getDerived().TransformDecl(E->getLocStart(), |
| 5388 | E->getOperatorDelete())); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5389 | if (!OperatorDelete) |
| 5390 | return SemaRef.ExprError(); |
| 5391 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5392 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5393 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5394 | Operand.get() == E->getArgument() && |
| 5395 | OperatorDelete == E->getOperatorDelete()) { |
| 5396 | // Mark any declarations we need as referenced. |
| 5397 | // FIXME: instantiation-specific. |
| 5398 | if (OperatorDelete) |
| 5399 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5400 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5402 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5403 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 5404 | E->isGlobalDelete(), |
| 5405 | E->isArrayForm(), |
| 5406 | move(Operand)); |
| 5407 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5408 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5409 | template<typename Derived> |
| 5410 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5411 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5412 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5413 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 5414 | if (Base.isInvalid()) |
| 5415 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5416 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5417 | Sema::TypeTy *ObjectTypePtr = 0; |
| 5418 | bool MayBePseudoDestructor = false; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5419 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5420 | E->getOperatorLoc(), |
| 5421 | E->isArrow()? tok::arrow : tok::period, |
| 5422 | ObjectTypePtr, |
| 5423 | MayBePseudoDestructor); |
| 5424 | if (Base.isInvalid()) |
| 5425 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5426 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5427 | QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5428 | NestedNameSpecifier *Qualifier |
| 5429 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | 90d554e | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 5430 | E->getQualifierRange(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5431 | ObjectType); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5432 | if (E->getQualifier() && !Qualifier) |
| 5433 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5435 | PseudoDestructorTypeStorage Destroyed; |
| 5436 | if (E->getDestroyedTypeInfo()) { |
| 5437 | TypeSourceInfo *DestroyedTypeInfo |
| 5438 | = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType); |
| 5439 | if (!DestroyedTypeInfo) |
| 5440 | return SemaRef.ExprError(); |
| 5441 | Destroyed = DestroyedTypeInfo; |
| 5442 | } else if (ObjectType->isDependentType()) { |
| 5443 | // We aren't likely to be able to resolve the identifier down to a type |
| 5444 | // now anyway, so just retain the identifier. |
| 5445 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 5446 | E->getDestroyedTypeLoc()); |
| 5447 | } else { |
| 5448 | // Look for a destructor known with the given name. |
| 5449 | CXXScopeSpec SS; |
| 5450 | if (Qualifier) { |
| 5451 | SS.setScopeRep(Qualifier); |
| 5452 | SS.setRange(E->getQualifierRange()); |
| 5453 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5454 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5455 | Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 5456 | *E->getDestroyedTypeIdentifier(), |
| 5457 | E->getDestroyedTypeLoc(), |
| 5458 | /*Scope=*/0, |
| 5459 | SS, ObjectTypePtr, |
| 5460 | false); |
| 5461 | if (!T) |
| 5462 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5463 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5464 | Destroyed |
| 5465 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 5466 | E->getDestroyedTypeLoc()); |
| 5467 | } |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5468 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5469 | TypeSourceInfo *ScopeTypeInfo = 0; |
| 5470 | if (E->getScopeTypeInfo()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5471 | ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5472 | ObjectType); |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5473 | if (!ScopeTypeInfo) |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5474 | return SemaRef.ExprError(); |
| 5475 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5476 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5477 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 5478 | E->getOperatorLoc(), |
| 5479 | E->isArrow(), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5480 | Qualifier, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 5481 | E->getQualifierRange(), |
| 5482 | ScopeTypeInfo, |
| 5483 | E->getColonColonLoc(), |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 5484 | E->getTildeLoc(), |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 5485 | Destroyed); |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5487 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 5488 | template<typename Derived> |
| 5489 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5490 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5491 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5492 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 5493 | |
| 5494 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 5495 | Sema::LookupOrdinaryName); |
| 5496 | |
| 5497 | // Transform all the decls. |
| 5498 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 5499 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5500 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5501 | getDerived().TransformDecl(Old->getNameLoc(), |
| 5502 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5503 | if (!InstD) { |
| 5504 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5505 | // This can happen because of dependent hiding. |
| 5506 | if (isa<UsingShadowDecl>(*I)) |
| 5507 | continue; |
| 5508 | else |
| 5509 | return SemaRef.ExprError(); |
| 5510 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5511 | |
| 5512 | // Expand using declarations. |
| 5513 | if (isa<UsingDecl>(InstD)) { |
| 5514 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5515 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5516 | E = UD->shadow_end(); I != E; ++I) |
| 5517 | R.addDecl(*I); |
| 5518 | continue; |
| 5519 | } |
| 5520 | |
| 5521 | R.addDecl(InstD); |
| 5522 | } |
| 5523 | |
| 5524 | // Resolve a kind, but don't do any further analysis. If it's |
| 5525 | // ambiguous, the callee needs to deal with it. |
| 5526 | R.resolveKind(); |
| 5527 | |
| 5528 | // Rebuild the nested-name qualifier, if present. |
| 5529 | CXXScopeSpec SS; |
| 5530 | NestedNameSpecifier *Qualifier = 0; |
| 5531 | if (Old->getQualifier()) { |
| 5532 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5533 | Old->getQualifierRange()); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5534 | if (!Qualifier) |
| 5535 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5536 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5537 | SS.setScopeRep(Qualifier); |
| 5538 | SS.setRange(Old->getQualifierRange()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5541 | if (Old->getNamingClass()) { |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5542 | CXXRecordDecl *NamingClass |
| 5543 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 5544 | Old->getNameLoc(), |
| 5545 | Old->getNamingClass())); |
| 5546 | if (!NamingClass) |
| 5547 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5548 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5549 | R.setNamingClass(NamingClass); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | // If we have no template arguments, it's a normal declaration name. |
| 5553 | if (!Old->hasExplicitTemplateArgs()) |
| 5554 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 5555 | |
| 5556 | // If we have template arguments, rebuild them, then rebuild the |
| 5557 | // templateid expression. |
| 5558 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 5559 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5560 | TemplateArgumentLoc Loc; |
| 5561 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 5562 | return SemaRef.ExprError(); |
| 5563 | TransArgs.addArgument(Loc); |
| 5564 | } |
| 5565 | |
| 5566 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 5567 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5569 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5570 | template<typename Derived> |
| 5571 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5572 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5573 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5575 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 5576 | if (T.isNull()) |
| 5577 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5579 | if (!getDerived().AlwaysRebuild() && |
| 5580 | T == E->getQueriedType()) |
| 5581 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5583 | // FIXME: Bad location information |
| 5584 | SourceLocation FakeLParenLoc |
| 5585 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5586 | |
| 5587 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5588 | E->getLocStart(), |
| 5589 | /*FIXME:*/FakeLParenLoc, |
| 5590 | T, |
| 5591 | E->getLocEnd()); |
| 5592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5594 | template<typename Derived> |
| 5595 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5596 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5597 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5598 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5599 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5600 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5601 | if (!NNS) |
| 5602 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5604 | DeclarationNameInfo NameInfo |
| 5605 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 5606 | if (!NameInfo.getName()) |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5607 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5608 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5609 | if (!E->hasExplicitTemplateArgs()) { |
| 5610 | if (!getDerived().AlwaysRebuild() && |
| 5611 | NNS == E->getQualifier() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5612 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 5613 | // if name has not changed, DNLoc has not changed either. |
| 5614 | NameInfo.getName() == E->getDeclName()) |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5615 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5616 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5617 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5618 | E->getQualifierRange(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5619 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5620 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 5621 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5622 | |
| 5623 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5624 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5625 | TemplateArgumentLoc Loc; |
| 5626 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5627 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5628 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5629 | } |
| 5630 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5631 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 5632 | E->getQualifierRange(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5633 | NameInfo, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 5634 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | template<typename Derived> |
| 5638 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5639 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 5640 | // CXXConstructExprs are always implicit, so when we have a |
| 5641 | // 1-argument construction we just transform that argument. |
| 5642 | if (E->getNumArgs() == 1 || |
| 5643 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 5644 | return getDerived().TransformExpr(E->getArg(0)); |
| 5645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5646 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 5647 | |
| 5648 | QualType T = getDerived().TransformType(E->getType()); |
| 5649 | if (T.isNull()) |
| 5650 | return SemaRef.ExprError(); |
| 5651 | |
| 5652 | CXXConstructorDecl *Constructor |
| 5653 | = cast_or_null<CXXConstructorDecl>( |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5654 | getDerived().TransformDecl(E->getLocStart(), |
| 5655 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5656 | if (!Constructor) |
| 5657 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5658 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5659 | bool ArgumentChanged = false; |
| 5660 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5661 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5662 | ArgEnd = E->arg_end(); |
| 5663 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 5664 | if (getDerived().DropCallArgument(*Arg)) { |
| 5665 | ArgumentChanged = true; |
| 5666 | break; |
| 5667 | } |
| 5668 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5669 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5670 | if (TransArg.isInvalid()) |
| 5671 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5672 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5673 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5674 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5675 | } |
| 5676 | |
| 5677 | if (!getDerived().AlwaysRebuild() && |
| 5678 | T == E->getType() && |
| 5679 | Constructor == E->getConstructor() && |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5680 | !ArgumentChanged) { |
Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 5681 | // Mark the constructor as referenced. |
| 5682 | // FIXME: Instantiation-specific |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5683 | SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 5685 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 5687 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 5688 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5689 | move_arg(Args)); |
| 5690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5692 | /// \brief Transform a C++ temporary-binding expression. |
| 5693 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5694 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 5695 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5696 | template<typename Derived> |
| 5697 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5698 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5699 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5701 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 5702 | /// \brief Transform a C++ reference-binding expression. |
| 5703 | /// |
| 5704 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 5705 | /// transform the subexpression and return that. |
| 5706 | template<typename Derived> |
| 5707 | Sema::OwningExprResult |
| 5708 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 5709 | return getDerived().TransformExpr(E->getSubExpr()); |
| 5710 | } |
| 5711 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5712 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5713 | /// be destroyed after the expression is evaluated. |
| 5714 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5715 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 5716 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5717 | template<typename Derived> |
| 5718 | Sema::OwningExprResult |
| 5719 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 5720 | CXXExprWithTemporaries *E) { |
| 5721 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5723 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5724 | template<typename Derived> |
| 5725 | Sema::OwningExprResult |
| 5726 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5727 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5728 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5729 | QualType T = getDerived().TransformType(E->getType()); |
| 5730 | if (T.isNull()) |
| 5731 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5732 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5733 | CXXConstructorDecl *Constructor |
| 5734 | = cast_or_null<CXXConstructorDecl>( |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5735 | getDerived().TransformDecl(E->getLocStart(), |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5736 | E->getConstructor())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5737 | if (!Constructor) |
| 5738 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5739 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5740 | bool ArgumentChanged = false; |
| 5741 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5742 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5743 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5744 | ArgEnd = E->arg_end(); |
| 5745 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5746 | if (getDerived().DropCallArgument(*Arg)) { |
| 5747 | ArgumentChanged = true; |
| 5748 | break; |
| 5749 | } |
| 5750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5751 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5752 | if (TransArg.isInvalid()) |
| 5753 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5754 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5755 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5756 | Args.push_back((Expr *)TransArg.release()); |
| 5757 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5758 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5759 | if (!getDerived().AlwaysRebuild() && |
| 5760 | T == E->getType() && |
| 5761 | Constructor == E->getConstructor() && |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5762 | !ArgumentChanged) { |
| 5763 | // FIXME: Instantiation-specific |
| 5764 | SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor); |
Chandler Carruth | b32b344 | 2010-03-31 18:34:58 +0000 | [diff] [blame] | 5765 | return SemaRef.MaybeBindToTemporary(E->Retain()); |
Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 5766 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5768 | // FIXME: Bogus location information |
| 5769 | SourceLocation CommaLoc; |
| 5770 | if (Args.size() > 1) { |
| 5771 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5772 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5773 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 5774 | } |
| 5775 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 5776 | T, |
| 5777 | /*FIXME:*/E->getTypeBeginLoc(), |
| 5778 | move_arg(Args), |
| 5779 | &CommaLoc, |
| 5780 | E->getLocEnd()); |
| 5781 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5782 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5783 | template<typename Derived> |
| 5784 | Sema::OwningExprResult |
| 5785 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5786 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5787 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 5788 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 5789 | if (T.isNull()) |
| 5790 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5791 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5792 | bool ArgumentChanged = false; |
| 5793 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 5794 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 5795 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 5796 | ArgEnd = E->arg_end(); |
| 5797 | Arg != ArgEnd; ++Arg) { |
| 5798 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 5799 | if (TransArg.isInvalid()) |
| 5800 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5801 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5802 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 5803 | FakeCommaLocs.push_back( |
| 5804 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 5805 | Args.push_back(TransArg.takeAs<Expr>()); |
| 5806 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5807 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5808 | if (!getDerived().AlwaysRebuild() && |
| 5809 | T == E->getTypeAsWritten() && |
| 5810 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5811 | return SemaRef.Owned(E->Retain()); |
| 5812 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5813 | // FIXME: we're faking the locations of the commas |
| 5814 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5815 | T, |
| 5816 | E->getLParenLoc(), |
| 5817 | move_arg(Args), |
| 5818 | FakeCommaLocs.data(), |
| 5819 | E->getRParenLoc()); |
| 5820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5821 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5822 | template<typename Derived> |
| 5823 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5824 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5825 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5826 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5827 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5828 | Expr *OldBase; |
| 5829 | QualType BaseType; |
| 5830 | QualType ObjectType; |
| 5831 | if (!E->isImplicitAccess()) { |
| 5832 | OldBase = E->getBase(); |
| 5833 | Base = getDerived().TransformExpr(OldBase); |
| 5834 | if (Base.isInvalid()) |
| 5835 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5836 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5837 | // Start the member reference and compute the object's type. |
| 5838 | Sema::TypeTy *ObjectTy = 0; |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5839 | bool MayBePseudoDestructor = false; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5840 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5841 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5842 | E->isArrow()? tok::arrow : tok::period, |
Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 5843 | ObjectTy, |
| 5844 | MayBePseudoDestructor); |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5845 | if (Base.isInvalid()) |
| 5846 | return SemaRef.ExprError(); |
| 5847 | |
| 5848 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5849 | BaseType = ((Expr*) Base.get())->getType(); |
| 5850 | } else { |
| 5851 | OldBase = 0; |
| 5852 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5853 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5854 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5855 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5856 | // Transform the first part of the nested-name-specifier that qualifies |
| 5857 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5858 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5859 | = getDerived().TransformFirstQualifierInScope( |
| 5860 | E->getFirstQualifierFoundInScope(), |
| 5861 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5862 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5863 | NestedNameSpecifier *Qualifier = 0; |
| 5864 | if (E->getQualifier()) { |
| 5865 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5866 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5867 | ObjectType, |
| 5868 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5869 | if (!Qualifier) |
| 5870 | return SemaRef.ExprError(); |
| 5871 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5873 | DeclarationNameInfo NameInfo |
| 5874 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo(), |
| 5875 | ObjectType); |
| 5876 | if (!NameInfo.getName()) |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5877 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5878 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5879 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5880 | // This is a reference to a member without an explicitly-specified |
| 5881 | // template argument list. Optimize for this common case. |
| 5882 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5883 | Base.get() == OldBase && |
| 5884 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5885 | Qualifier == E->getQualifier() && |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5886 | NameInfo.getName() == E->getMember() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5887 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5888 | return SemaRef.Owned(E->Retain()); |
| 5889 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5890 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5891 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5892 | E->isArrow(), |
| 5893 | E->getOperatorLoc(), |
| 5894 | Qualifier, |
| 5895 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5896 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5897 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5898 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5899 | } |
| 5900 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5901 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5902 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5903 | TemplateArgumentLoc Loc; |
| 5904 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5905 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5906 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5907 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5908 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5909 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5910 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5911 | E->isArrow(), |
| 5912 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5913 | Qualifier, |
| 5914 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5915 | FirstQualifierInScope, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5916 | NameInfo, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5917 | &TransArgs); |
| 5918 | } |
| 5919 | |
| 5920 | template<typename Derived> |
| 5921 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5922 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5923 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5924 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5925 | QualType BaseType; |
| 5926 | if (!Old->isImplicitAccess()) { |
| 5927 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5928 | if (Base.isInvalid()) |
| 5929 | return SemaRef.ExprError(); |
| 5930 | BaseType = ((Expr*) Base.get())->getType(); |
| 5931 | } else { |
| 5932 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5933 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5934 | |
| 5935 | NestedNameSpecifier *Qualifier = 0; |
| 5936 | if (Old->getQualifier()) { |
| 5937 | Qualifier |
| 5938 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 5939 | Old->getQualifierRange()); |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5940 | if (Qualifier == 0) |
| 5941 | return SemaRef.ExprError(); |
| 5942 | } |
| 5943 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 5944 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5945 | Sema::LookupOrdinaryName); |
| 5946 | |
| 5947 | // Transform all the decls. |
| 5948 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5949 | E = Old->decls_end(); I != E; ++I) { |
Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5950 | NamedDecl *InstD = static_cast<NamedDecl*>( |
| 5951 | getDerived().TransformDecl(Old->getMemberLoc(), |
| 5952 | *I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5953 | if (!InstD) { |
| 5954 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5955 | // This can happen because of dependent hiding. |
| 5956 | if (isa<UsingShadowDecl>(*I)) |
| 5957 | continue; |
| 5958 | else |
| 5959 | return SemaRef.ExprError(); |
| 5960 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5961 | |
| 5962 | // Expand using declarations. |
| 5963 | if (isa<UsingDecl>(InstD)) { |
| 5964 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5965 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5966 | E = UD->shadow_end(); I != E; ++I) |
| 5967 | R.addDecl(*I); |
| 5968 | continue; |
| 5969 | } |
| 5970 | |
| 5971 | R.addDecl(InstD); |
| 5972 | } |
| 5973 | |
| 5974 | R.resolveKind(); |
| 5975 | |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5976 | // Determine the naming class. |
Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 5977 | if (Old->getNamingClass()) { |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5978 | CXXRecordDecl *NamingClass |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5979 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5980 | Old->getMemberLoc(), |
| 5981 | Old->getNamingClass())); |
| 5982 | if (!NamingClass) |
| 5983 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5984 | |
Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 5985 | R.setNamingClass(NamingClass); |
Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 5986 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 5987 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5988 | TemplateArgumentListInfo TransArgs; |
| 5989 | if (Old->hasExplicitTemplateArgs()) { |
| 5990 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5991 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5992 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5993 | TemplateArgumentLoc Loc; |
| 5994 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5995 | Loc)) |
| 5996 | return SemaRef.ExprError(); |
| 5997 | TransArgs.addArgument(Loc); |
| 5998 | } |
| 5999 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6000 | |
| 6001 | // FIXME: to do this check properly, we will need to preserve the |
| 6002 | // first-qualifier-in-scope here, just in case we had a dependent |
| 6003 | // base (and therefore couldn't do the check) and a |
| 6004 | // nested-name-qualifier (and therefore could do the lookup). |
| 6005 | NamedDecl *FirstQualifierInScope = 0; |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6006 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6007 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 6008 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6009 | Old->getOperatorLoc(), |
| 6010 | Old->isArrow(), |
| 6011 | Qualifier, |
| 6012 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 6013 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 6014 | R, |
| 6015 | (Old->hasExplicitTemplateArgs() |
| 6016 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | template<typename Derived> |
| 6020 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6021 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6022 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6023 | } |
| 6024 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6025 | template<typename Derived> |
| 6026 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6027 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6028 | TypeSourceInfo *EncodedTypeInfo |
| 6029 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 6030 | if (!EncodedTypeInfo) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6031 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6033 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6034 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6035 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6036 | |
| 6037 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 6038 | EncodedTypeInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6039 | E->getRParenLoc()); |
| 6040 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6041 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6042 | template<typename Derived> |
| 6043 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6044 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6045 | // Transform arguments. |
| 6046 | bool ArgChanged = false; |
| 6047 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 6048 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 6049 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 6050 | if (Arg.isInvalid()) |
| 6051 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6052 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6053 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
| 6054 | Args.push_back(Arg.takeAs<Expr>()); |
| 6055 | } |
| 6056 | |
| 6057 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 6058 | // Class message: transform the receiver type. |
| 6059 | TypeSourceInfo *ReceiverTypeInfo |
| 6060 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 6061 | if (!ReceiverTypeInfo) |
| 6062 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6063 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6064 | // If nothing changed, just retain the existing message send. |
| 6065 | if (!getDerived().AlwaysRebuild() && |
| 6066 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 6067 | return SemaRef.Owned(E->Retain()); |
| 6068 | |
| 6069 | // Build a new class message send. |
| 6070 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 6071 | E->getSelector(), |
| 6072 | E->getMethodDecl(), |
| 6073 | E->getLeftLoc(), |
| 6074 | move_arg(Args), |
| 6075 | E->getRightLoc()); |
| 6076 | } |
| 6077 | |
| 6078 | // Instance message: transform the receiver |
| 6079 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 6080 | "Only class and instance messages may be instantiated"); |
| 6081 | OwningExprResult Receiver |
| 6082 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 6083 | if (Receiver.isInvalid()) |
| 6084 | return SemaRef.ExprError(); |
| 6085 | |
| 6086 | // If nothing changed, just retain the existing message send. |
| 6087 | if (!getDerived().AlwaysRebuild() && |
| 6088 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 6089 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6090 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6091 | // Build a new instance message send. |
| 6092 | return getDerived().RebuildObjCMessageExpr(move(Receiver), |
| 6093 | E->getSelector(), |
| 6094 | E->getMethodDecl(), |
| 6095 | E->getLeftLoc(), |
| 6096 | move_arg(Args), |
| 6097 | E->getRightLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6098 | } |
| 6099 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6100 | template<typename Derived> |
| 6101 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6102 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6103 | return SemaRef.Owned(E->Retain()); |
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6109 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6110 | } |
| 6111 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6112 | template<typename Derived> |
| 6113 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6114 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6115 | // Transform the base expression. |
| 6116 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6117 | if (Base.isInvalid()) |
| 6118 | return SemaRef.ExprError(); |
| 6119 | |
| 6120 | // We don't need to transform the ivar; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6121 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6122 | // If nothing changed, just retain the existing expression. |
| 6123 | if (!getDerived().AlwaysRebuild() && |
| 6124 | Base.get() == E->getBase()) |
| 6125 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6126 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6127 | return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), |
| 6128 | E->getLocation(), |
| 6129 | E->isArrow(), E->isFreeIvar()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6130 | } |
| 6131 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6132 | template<typename Derived> |
| 6133 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6134 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6135 | // Transform the base expression. |
| 6136 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6137 | if (Base.isInvalid()) |
| 6138 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6139 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6140 | // We don't need to transform the property; it will never change. |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6141 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6142 | // If nothing changed, just retain the existing expression. |
| 6143 | if (!getDerived().AlwaysRebuild() && |
| 6144 | Base.get() == E->getBase()) |
| 6145 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6146 | |
Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 6147 | return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), |
| 6148 | E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6149 | } |
| 6150 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6151 | template<typename Derived> |
| 6152 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 6153 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6154 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6155 | // If this implicit setter/getter refers to class methods, it cannot have any |
| 6156 | // dependent parts. Just retain the existing declaration. |
| 6157 | if (E->getInterfaceDecl()) |
| 6158 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6159 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6160 | // Transform the base expression. |
| 6161 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6162 | if (Base.isInvalid()) |
| 6163 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6164 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6165 | // 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] | 6166 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6167 | // If nothing changed, just retain the existing expression. |
| 6168 | if (!getDerived().AlwaysRebuild() && |
| 6169 | Base.get() == E->getBase()) |
| 6170 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6171 | |
Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 6172 | return getDerived().RebuildObjCImplicitSetterGetterRefExpr( |
| 6173 | E->getGetterMethod(), |
| 6174 | E->getType(), |
| 6175 | E->getSetterMethod(), |
| 6176 | E->getLocation(), |
| 6177 | move(Base)); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6178 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6181 | template<typename Derived> |
| 6182 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6183 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6184 | // Can never occur in a dependent context. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6185 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6188 | template<typename Derived> |
| 6189 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6190 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6191 | // Transform the base expression. |
| 6192 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 6193 | if (Base.isInvalid()) |
| 6194 | return SemaRef.ExprError(); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6195 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6196 | // If nothing changed, just retain the existing expression. |
| 6197 | if (!getDerived().AlwaysRebuild() && |
| 6198 | Base.get() == E->getBase()) |
| 6199 | return SemaRef.Owned(E->Retain()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6200 | |
Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 6201 | return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), |
| 6202 | E->isArrow()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6203 | } |
| 6204 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6205 | template<typename Derived> |
| 6206 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6207 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6208 | bool ArgumentChanged = false; |
| 6209 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 6210 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 6211 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 6212 | if (SubExpr.isInvalid()) |
| 6213 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6214 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6215 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 6216 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 6217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6219 | if (!getDerived().AlwaysRebuild() && |
| 6220 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6221 | return SemaRef.Owned(E->Retain()); |
| 6222 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6223 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 6224 | move_arg(SubExprs), |
| 6225 | E->getRParenLoc()); |
| 6226 | } |
| 6227 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6228 | template<typename Derived> |
| 6229 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6230 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6231 | SourceLocation CaretLoc(E->getExprLoc()); |
| 6232 | |
| 6233 | SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0); |
| 6234 | BlockScopeInfo *CurBlock = SemaRef.getCurBlock(); |
| 6235 | CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic()); |
| 6236 | llvm::SmallVector<ParmVarDecl*, 4> Params; |
| 6237 | llvm::SmallVector<QualType, 4> ParamTypes; |
| 6238 | |
| 6239 | // Parameter substitution. |
| 6240 | const BlockDecl *BD = E->getBlockDecl(); |
| 6241 | for (BlockDecl::param_const_iterator P = BD->param_begin(), |
| 6242 | EN = BD->param_end(); P != EN; ++P) { |
| 6243 | ParmVarDecl *OldParm = (*P); |
| 6244 | ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm); |
| 6245 | QualType NewType = NewParm->getType(); |
| 6246 | Params.push_back(NewParm); |
| 6247 | ParamTypes.push_back(NewParm->getType()); |
| 6248 | } |
| 6249 | |
| 6250 | const FunctionType *BExprFunctionType = E->getFunctionType(); |
| 6251 | QualType BExprResultType = BExprFunctionType->getResultType(); |
| 6252 | if (!BExprResultType.isNull()) { |
| 6253 | if (!BExprResultType->isDependentType()) |
| 6254 | CurBlock->ReturnType = BExprResultType; |
| 6255 | else if (BExprResultType != SemaRef.Context.DependentTy) |
| 6256 | CurBlock->ReturnType = getDerived().TransformType(BExprResultType); |
| 6257 | } |
| 6258 | |
| 6259 | // Transform the body |
| 6260 | OwningStmtResult Body = getDerived().TransformStmt(E->getBody()); |
| 6261 | if (Body.isInvalid()) |
| 6262 | return SemaRef.ExprError(); |
| 6263 | // Set the parameters on the block decl. |
| 6264 | if (!Params.empty()) |
| 6265 | CurBlock->TheDecl->setParams(Params.data(), Params.size()); |
| 6266 | |
| 6267 | QualType FunctionType = getDerived().RebuildFunctionProtoType( |
| 6268 | CurBlock->ReturnType, |
| 6269 | ParamTypes.data(), |
| 6270 | ParamTypes.size(), |
| 6271 | BD->isVariadic(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6272 | 0, |
| 6273 | BExprFunctionType->getExtInfo()); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6274 | |
| 6275 | CurBlock->FunctionType = FunctionType; |
| 6276 | return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6279 | template<typename Derived> |
| 6280 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 6281 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6282 | NestedNameSpecifier *Qualifier = 0; |
| 6283 | |
| 6284 | ValueDecl *ND |
| 6285 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 6286 | E->getDecl())); |
| 6287 | if (!ND) |
| 6288 | return SemaRef.ExprError(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6289 | |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6290 | if (!getDerived().AlwaysRebuild() && |
| 6291 | ND == E->getDecl()) { |
| 6292 | // Mark it referenced in the new context regardless. |
| 6293 | // FIXME: this is a bit instantiation-specific. |
| 6294 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 6295 | |
| 6296 | return SemaRef.Owned(E->Retain()); |
| 6297 | } |
| 6298 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6299 | DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); |
Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 6300 | return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(), |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6301 | ND, NameInfo, 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6304 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6305 | // Type reconstruction |
| 6306 | //===----------------------------------------------------------------------===// |
| 6307 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6308 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6309 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 6310 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6311 | return SemaRef.BuildPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6312 | getDerived().getBaseEntity()); |
| 6313 | } |
| 6314 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6315 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6316 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 6317 | SourceLocation Star) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6318 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6319 | getDerived().getBaseEntity()); |
| 6320 | } |
| 6321 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6322 | template<typename Derived> |
| 6323 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6324 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 6325 | bool WrittenAsLValue, |
| 6326 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6327 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6328 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6332 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6333 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 6334 | QualType ClassType, |
| 6335 | SourceLocation Sigil) { |
John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 6336 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6337 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
| 6340 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6341 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6342 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 6343 | ArrayType::ArraySizeModifier SizeMod, |
| 6344 | const llvm::APInt *Size, |
| 6345 | Expr *SizeExpr, |
| 6346 | unsigned IndexTypeQuals, |
| 6347 | SourceRange BracketsRange) { |
| 6348 | if (SizeExpr || !Size) |
| 6349 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 6350 | IndexTypeQuals, BracketsRange, |
| 6351 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6352 | |
| 6353 | QualType Types[] = { |
| 6354 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 6355 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 6356 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6357 | }; |
| 6358 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 6359 | QualType SizeType; |
| 6360 | for (unsigned I = 0; I != NumTypes; ++I) |
| 6361 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 6362 | SizeType = Types[I]; |
| 6363 | break; |
| 6364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6365 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6366 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6367 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6368 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6369 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6371 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6372 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6373 | QualType |
| 6374 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6375 | ArrayType::ArraySizeModifier SizeMod, |
| 6376 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6377 | unsigned IndexTypeQuals, |
| 6378 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6379 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6380 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6384 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6385 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6386 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6387 | unsigned IndexTypeQuals, |
| 6388 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6389 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 6390 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6392 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6393 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6394 | QualType |
| 6395 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6396 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6397 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6398 | unsigned IndexTypeQuals, |
| 6399 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6400 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6401 | SizeExpr.takeAs<Expr>(), |
| 6402 | IndexTypeQuals, BracketsRange); |
| 6403 | } |
| 6404 | |
| 6405 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6406 | QualType |
| 6407 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6408 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6409 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6410 | unsigned IndexTypeQuals, |
| 6411 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6412 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6413 | SizeExpr.takeAs<Expr>(), |
| 6414 | IndexTypeQuals, BracketsRange); |
| 6415 | } |
| 6416 | |
| 6417 | template<typename Derived> |
| 6418 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6419 | unsigned NumElements, |
| 6420 | VectorType::AltiVecSpecific AltiVecSpec) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6421 | // FIXME: semantic checking! |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 6422 | return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6424 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6425 | template<typename Derived> |
| 6426 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 6427 | unsigned NumElements, |
| 6428 | SourceLocation AttributeLoc) { |
| 6429 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 6430 | NumElements, true); |
| 6431 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6432 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6433 | AttributeLoc); |
| 6434 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 6435 | AttributeLoc); |
| 6436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6437 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6438 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6439 | QualType |
| 6440 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6441 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6442 | SourceLocation AttributeLoc) { |
| 6443 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 6444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6445 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6446 | template<typename Derived> |
| 6447 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6448 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6449 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6450 | bool Variadic, |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6451 | unsigned Quals, |
| 6452 | const FunctionType::ExtInfo &Info) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6453 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6454 | Quals, |
| 6455 | getDerived().getBaseLocation(), |
Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 6456 | getDerived().getBaseEntity(), |
| 6457 | Info); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6458 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6459 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6460 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6461 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 6462 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 6463 | } |
| 6464 | |
| 6465 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6466 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 6467 | assert(D && "no decl found"); |
| 6468 | if (D->isInvalidDecl()) return QualType(); |
| 6469 | |
Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 6470 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6471 | TypeDecl *Ty; |
| 6472 | if (isa<UsingDecl>(D)) { |
| 6473 | UsingDecl *Using = cast<UsingDecl>(D); |
| 6474 | assert(Using->isTypeName() && |
| 6475 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 6476 | |
| 6477 | // A valid resolved using typename decl points to exactly one type decl. |
| 6478 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 6479 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6480 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 6481 | } else { |
| 6482 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 6483 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 6484 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 6485 | } |
| 6486 | |
| 6487 | return SemaRef.Context.getTypeDeclType(Ty); |
| 6488 | } |
| 6489 | |
| 6490 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6491 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6492 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 6493 | } |
| 6494 | |
| 6495 | template<typename Derived> |
| 6496 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 6497 | return SemaRef.Context.getTypeOfType(Underlying); |
| 6498 | } |
| 6499 | |
| 6500 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6501 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6502 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 6503 | } |
| 6504 | |
| 6505 | template<typename Derived> |
| 6506 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6507 | TemplateName Template, |
| 6508 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6509 | const TemplateArgumentListInfo &TemplateArgs) { |
| 6510 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6512 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6513 | template<typename Derived> |
| 6514 | NestedNameSpecifier * |
| 6515 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6516 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 6517 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6518 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6519 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6520 | CXXScopeSpec SS; |
| 6521 | // FIXME: The source location information is all wrong. |
| 6522 | SS.setRange(Range); |
| 6523 | SS.setScopeRep(Prefix); |
| 6524 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6525 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 6526 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 6527 | ObjectType, |
| 6528 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 6529 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
| 6532 | template<typename Derived> |
| 6533 | NestedNameSpecifier * |
| 6534 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6535 | SourceRange Range, |
| 6536 | NamespaceDecl *NS) { |
| 6537 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 6538 | } |
| 6539 | |
| 6540 | template<typename Derived> |
| 6541 | NestedNameSpecifier * |
| 6542 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 6543 | SourceRange Range, |
| 6544 | bool TemplateKW, |
Douglas Gregor | cd3f49f | 2010-02-25 04:46:04 +0000 | [diff] [blame] | 6545 | QualType T) { |
| 6546 | if (T->isDependentType() || T->isRecordType() || |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6547 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 6548 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6549 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 6550 | T.getTypePtr()); |
| 6551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6552 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 6553 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 6554 | return 0; |
| 6555 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6556 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6557 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6558 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6559 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6560 | bool TemplateKW, |
| 6561 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6562 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6563 | Template); |
| 6564 | } |
| 6565 | |
| 6566 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6567 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6568 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 6569 | const IdentifierInfo &II, |
| 6570 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6571 | CXXScopeSpec SS; |
| 6572 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6573 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 6574 | UnqualifiedId Name; |
| 6575 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6576 | Sema::TemplateTy Template; |
| 6577 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
| 6578 | /*FIXME:*/getDerived().getBaseLocation(), |
| 6579 | SS, |
| 6580 | Name, |
| 6581 | ObjectType.getAsOpaquePtr(), |
| 6582 | /*EnteringContext=*/false, |
| 6583 | Template); |
| 6584 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 6585 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6586 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6587 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6588 | TemplateName |
| 6589 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 6590 | OverloadedOperatorKind Operator, |
| 6591 | QualType ObjectType) { |
| 6592 | CXXScopeSpec SS; |
| 6593 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 6594 | SS.setScopeRep(Qualifier); |
| 6595 | UnqualifiedId Name; |
| 6596 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 6597 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 6598 | Operator, SymbolLocations); |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6599 | Sema::TemplateTy Template; |
| 6600 | getSema().ActOnDependentTemplateName(/*Scope=*/0, |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6601 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 6602 | SS, |
| 6603 | Name, |
| 6604 | ObjectType.getAsOpaquePtr(), |
| 6605 | /*EnteringContext=*/false, |
| 6606 | Template); |
| 6607 | return Template.template getAsVal<TemplateName>(); |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6608 | } |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6609 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 6610 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6611 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6612 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 6613 | SourceLocation OpLoc, |
| 6614 | ExprArg Callee, |
| 6615 | ExprArg First, |
| 6616 | ExprArg Second) { |
| 6617 | Expr *FirstExpr = (Expr *)First.get(); |
| 6618 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6619 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6620 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6621 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6622 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6623 | if (Op == OO_Subscript) { |
| 6624 | if (!FirstExpr->getType()->isOverloadableType() && |
| 6625 | !SecondExpr->getType()->isOverloadableType()) |
| 6626 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6627 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6628 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 6629 | } else if (Op == OO_Arrow) { |
| 6630 | // -> is never a builtin operation. |
| 6631 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6632 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6633 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 6634 | // The argument is not of overloadable type, so try to create a |
| 6635 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6636 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6637 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6638 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6639 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 6640 | } |
| 6641 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6642 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6643 | !SecondExpr->getType()->isOverloadableType()) { |
| 6644 | // Neither of the arguments is an overloadable type, so try to |
| 6645 | // create a built-in binary operation. |
| 6646 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6647 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6648 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 6649 | if (Result.isInvalid()) |
| 6650 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6652 | First.release(); |
| 6653 | Second.release(); |
| 6654 | return move(Result); |
| 6655 | } |
| 6656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6657 | |
| 6658 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6659 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6660 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6661 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6662 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 6663 | assert(ULE->requiresADL()); |
| 6664 | |
| 6665 | // FIXME: Do we have to check |
| 6666 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6667 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6668 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 6669 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6670 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6671 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6672 | // Add any functions found via argument-dependent lookup. |
| 6673 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 6674 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6675 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6676 | // Create the overloaded operator invocation for unary operators. |
| 6677 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6678 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6679 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 6680 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 6681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6682 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6683 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 6684 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 6685 | OpLoc, |
| 6686 | move(First), |
| 6687 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 6688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6689 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6690 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6691 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6692 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6693 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 6694 | if (Result.isInvalid()) |
| 6695 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6696 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6697 | First.release(); |
| 6698 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6699 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 6700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6701 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6702 | template<typename Derived> |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6703 | Sema::OwningExprResult |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6704 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 6705 | SourceLocation OperatorLoc, |
| 6706 | bool isArrow, |
| 6707 | NestedNameSpecifier *Qualifier, |
| 6708 | SourceRange QualifierRange, |
| 6709 | TypeSourceInfo *ScopeType, |
| 6710 | SourceLocation CCLoc, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6711 | SourceLocation TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6712 | PseudoDestructorTypeStorage Destroyed) { |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6713 | CXXScopeSpec SS; |
| 6714 | if (Qualifier) { |
| 6715 | SS.setRange(QualifierRange); |
| 6716 | SS.setScopeRep(Qualifier); |
| 6717 | } |
| 6718 | |
| 6719 | Expr *BaseE = (Expr *)Base.get(); |
| 6720 | QualType BaseType = BaseE->getType(); |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6721 | if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6722 | (!isArrow && !BaseType->getAs<RecordType>()) || |
Alexis Hunt | a8136cc | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 6723 | (isArrow && BaseType->getAs<PointerType>() && |
Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 6724 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 6725 | ->template getAs<RecordType>())){ |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6726 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 6727 | return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, |
| 6728 | isArrow? tok::arrow : tok::period, |
Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 6729 | SS, ScopeType, CCLoc, TildeLoc, |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6730 | Destroyed, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6731 | /*FIXME?*/true); |
| 6732 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6733 | |
Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 6734 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6735 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 6736 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 6737 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 6738 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 6739 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6740 | // FIXME: the ScopeType should be tacked onto SS. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6741 | |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6742 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 6743 | OperatorLoc, isArrow, |
| 6744 | SS, /*FIXME: FirstQualifier*/ 0, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 6745 | NameInfo, |
Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 6746 | /*TemplateArgs*/ 0); |
| 6747 | } |
| 6748 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6749 | } // end namespace clang |
| 6750 | |
| 6751 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |