John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "Sema.h" |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 23 | #include "clang/AST/Stmt.h" |
| 24 | #include "clang/AST/StmtCXX.h" |
| 25 | #include "clang/AST/StmtObjC.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 27 | #include "clang/Parse/Ownership.h" |
| 28 | #include "clang/Parse/Designator.h" |
| 29 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | /// \brief A semantic tree transformation that allows one to transform one |
| 36 | /// abstract syntax tree into another. |
| 37 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 39 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 40 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 41 | /// instantiation is implemented as a tree transformation where the |
| 42 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 43 | /// template arguments for their corresponding template parameters; a similar |
| 44 | /// transformation is performed for non-type template parameters and |
| 45 | /// template template parameters. |
| 46 | /// |
| 47 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// override any of the transformation or rebuild operators by providing an |
| 50 | /// operation with the same signature as the default implementation. The |
| 51 | /// overridding function should not be virtual. |
| 52 | /// |
| 53 | /// Semantic tree transformations are split into two stages, either of which |
| 54 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 55 | /// or the parts of an AST node using the various transformation functions, |
| 56 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 57 | /// node of the appropriate kind from the pieces. The default transformation |
| 58 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 59 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 60 | /// were changed by the transformation, invokes the rebuild operation to create |
| 61 | /// a new AST node. |
| 62 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 65 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 66 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 67 | /// new implementations. |
| 68 | /// |
| 69 | /// For more fine-grained transformations, subclasses can replace any of the |
| 70 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 75 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 76 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 77 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 78 | /// be able to use more efficient rebuild steps. |
| 79 | /// |
| 80 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 83 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 84 | /// default locations and entity names used for type-checking |
| 85 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 92 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 93 | typedef Sema::OwningExprResult OwningExprResult; |
| 94 | typedef Sema::StmtArg StmtArg; |
| 95 | typedef Sema::ExprArg ExprArg; |
| 96 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 103 | /// \brief Retrieves a reference to the derived class. |
| 104 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 105 | |
| 106 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 112 | /// this tree transform. |
| 113 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 115 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 116 | /// if none of the children have changed. |
| 117 | /// |
| 118 | /// Subclasses may override this function to specify when the transformation |
| 119 | /// should rebuild all AST nodes. |
| 120 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Returns the location of the entity being transformed, if that |
| 123 | /// information was not available elsewhere in the AST. |
| 124 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 126 | /// provide an alternative implementation that provides better location |
| 127 | /// information. |
| 128 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | /// \brief Returns the name of the entity being transformed, if that |
| 131 | /// information was not available elsewhere in the AST. |
| 132 | /// |
| 133 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 134 | /// implementation with a more precise name. |
| 135 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 137 | /// \brief Sets the "base" location and entity when that |
| 138 | /// information is known based on another transformation. |
| 139 | /// |
| 140 | /// By default, the source location and entity are ignored. Subclasses can |
| 141 | /// override this function to provide a customized implementation. |
| 142 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 144 | /// \brief RAII object that temporarily sets the base location and entity |
| 145 | /// used for reporting diagnostics in types. |
| 146 | class TemporaryBase { |
| 147 | TreeTransform &Self; |
| 148 | SourceLocation OldLocation; |
| 149 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | OldLocation = Self.getDerived().getBaseLocation(); |
| 155 | OldEntity = Self.getDerived().getBaseEntity(); |
| 156 | Self.getDerived().setBase(Location, Entity); |
| 157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 169 | /// not change. For example, template instantiation need not traverse |
| 170 | /// non-dependent types. |
| 171 | bool AlreadyTransformed(QualType T) { |
| 172 | return T.isNull(); |
| 173 | } |
| 174 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 175 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 176 | /// because it is a default argument. |
| 177 | /// |
| 178 | /// Subclasses can provide an alternative implementation of this routine to |
| 179 | /// determine which kinds of call arguments get dropped. By default, |
| 180 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 181 | bool DropCallArgument(Expr *E) { |
| 182 | return E->isDefaultArgument(); |
| 183 | } |
| 184 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 189 | /// function. This is expensive, but we don't mind, because |
| 190 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
| 194 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 196 | /// \brief Transforms the given type-with-location into a new |
| 197 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 199 | /// By default, this routine transforms a type by delegating to the |
| 200 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 201 | /// may override this function (to take over all type |
| 202 | /// transformations) or some set of the TransformXXXType functions |
| 203 | /// to alter the transformation. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
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 | /// |
| 210 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 212 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 213 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 214 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 215 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 216 | /// statement or the TransformExpr() function to transform an expression. |
| 217 | /// Subclasses may override this function to transform statements using some |
| 218 | /// other mechanism. |
| 219 | /// |
| 220 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 221 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 222 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 223 | /// \brief Transform the given expression. |
| 224 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 225 | /// By default, this routine transforms an expression by delegating to the |
| 226 | /// appropriate TransformXXXExpr function to build a new expression. |
| 227 | /// Subclasses may override this function to transform expressions using some |
| 228 | /// other mechanism. |
| 229 | /// |
| 230 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 231 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 233 | /// \brief Transform the given declaration, which is referenced from a type |
| 234 | /// or expression. |
| 235 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 236 | /// By default, acts as the identity function on declarations. Subclasses |
| 237 | /// may override this function to provide alternate behavior. |
| 238 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 239 | |
| 240 | /// \brief Transform the definition of the given declaration. |
| 241 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 243 | /// Subclasses may override this function to provide alternate behavior. |
| 244 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 246 | /// \brief Transform the given declaration, which was the first part of a |
| 247 | /// nested-name-specifier in a member access expression. |
| 248 | /// |
| 249 | /// This specific declaration transformation only applies to the first |
| 250 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 251 | /// the \c T in \c x->T::member |
| 252 | /// |
| 253 | /// By default, invokes TransformDecl() to transform the declaration. |
| 254 | /// Subclasses may override this function to provide alternate behavior. |
| 255 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 256 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 257 | } |
| 258 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 259 | /// \brief Transform the given nested-name-specifier. |
| 260 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 262 | /// nested-name-specifier. Subclasses may override this function to provide |
| 263 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 264 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 265 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 266 | QualType ObjectType = QualType(), |
| 267 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 269 | /// \brief Transform the given declaration name. |
| 270 | /// |
| 271 | /// By default, transforms the types of conversion function, constructor, |
| 272 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 273 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 274 | /// override this function to provide alternate behavior. |
| 275 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 276 | SourceLocation Loc, |
| 277 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 281 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 284 | TemplateName TransformTemplateName(TemplateName Name, |
| 285 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 287 | /// \brief Transform the given template argument. |
| 288 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | /// By default, this operation transforms the type, expression, or |
| 290 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 291 | /// new template argument from the transformed result. Subclasses may |
| 292 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 293 | /// |
| 294 | /// Returns true if there was an error. |
| 295 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 296 | TemplateArgumentLoc &Output); |
| 297 | |
| 298 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 299 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 300 | TemplateArgumentLoc &ArgLoc); |
| 301 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 302 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 303 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 304 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 305 | getDerived().getBaseLocation()); |
| 306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 308 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 309 | #define TYPELOC(CLASS, PARENT) \ |
| 310 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 311 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 312 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 313 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 314 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 315 | QualType |
| 316 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 317 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 318 | |
| 319 | QualType |
| 320 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 321 | TemplateSpecializationTypeLoc TL, |
| 322 | QualType ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | #define STMT(Node, Parent) \ |
| 327 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 328 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 329 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define ABSTRACT_EXPR(Node, Parent) |
| 331 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 333 | /// \brief Build a new pointer type given its pointee type. |
| 334 | /// |
| 335 | /// By default, performs semantic analysis when building the pointer type. |
| 336 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 337 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | |
| 339 | /// \brief Build a new block pointer type given its pointee type. |
| 340 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 342 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 343 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// By default, performs semantic analysis when building the |
| 348 | /// reference type. Subclasses may override this routine to provide |
| 349 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 351 | /// \param LValue whether the type was written with an lvalue sigil |
| 352 | /// or an rvalue sigil. |
| 353 | QualType RebuildReferenceType(QualType ReferentType, |
| 354 | bool LValue, |
| 355 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 357 | /// \brief Build a new member pointer type given the pointee type and the |
| 358 | /// class type it refers into. |
| 359 | /// |
| 360 | /// By default, performs semantic analysis when building the member pointer |
| 361 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 363 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 365 | /// \brief Build a new Objective C object pointer type. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 366 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 367 | SourceLocation Sigil); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 369 | /// \brief Build a new array type given the element type, size |
| 370 | /// modifier, size of the array (if known), size expression, and index type |
| 371 | /// qualifiers. |
| 372 | /// |
| 373 | /// By default, performs semantic analysis when building the array type. |
| 374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | QualType RebuildArrayType(QualType ElementType, |
| 377 | ArrayType::ArraySizeModifier SizeMod, |
| 378 | const llvm::APInt *Size, |
| 379 | Expr *SizeExpr, |
| 380 | unsigned IndexTypeQuals, |
| 381 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | /// \brief Build a new constant array type given the element type, size |
| 384 | /// modifier, (known) size of the array, and index type qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 391 | unsigned IndexTypeQuals, |
| 392 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | /// \brief Build a new incomplete array type given the element type, size |
| 395 | /// modifier, and index type qualifiers. |
| 396 | /// |
| 397 | /// By default, performs semantic analysis when building the array type. |
| 398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 400 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 401 | unsigned IndexTypeQuals, |
| 402 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 403 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// size modifier, size expression, and index type qualifiers. |
| 406 | /// |
| 407 | /// By default, performs semantic analysis when building the array type. |
| 408 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | unsigned IndexTypeQuals, |
| 413 | SourceRange BracketsRange); |
| 414 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | /// size modifier, size expression, and index type qualifiers. |
| 417 | /// |
| 418 | /// By default, performs semantic analysis when building the array type. |
| 419 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | unsigned IndexTypeQuals, |
| 424 | SourceRange BracketsRange); |
| 425 | |
| 426 | /// \brief Build a new vector type given the element type and |
| 427 | /// number of elements. |
| 428 | /// |
| 429 | /// By default, performs semantic analysis when building the vector type. |
| 430 | /// Subclasses may override this routine to provide different behavior. |
| 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | /// \brief Build a new extended vector type given the element type and |
| 434 | /// number of elements. |
| 435 | /// |
| 436 | /// By default, performs semantic analysis when building the vector type. |
| 437 | /// Subclasses may override this routine to provide different behavior. |
| 438 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 439 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
| 441 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 442 | /// given the element type and number of elements. |
| 443 | /// |
| 444 | /// By default, performs semantic analysis when building the vector type. |
| 445 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 447 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 448 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new function type. |
| 451 | /// |
| 452 | /// By default, performs semantic analysis when building the function type. |
| 453 | /// Subclasses may override this routine to provide different behavior. |
| 454 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | unsigned NumParamTypes, |
| 457 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 459 | /// \brief Build a new unprototyped function type. |
| 460 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 461 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 462 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 463 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 464 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 465 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 466 | /// \brief Build a new typedef type. |
| 467 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 468 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 469 | } |
| 470 | |
| 471 | /// \brief Build a new class/struct/union type. |
| 472 | QualType RebuildRecordType(RecordDecl *Record) { |
| 473 | return SemaRef.Context.getTypeDeclType(Record); |
| 474 | } |
| 475 | |
| 476 | /// \brief Build a new Enum type. |
| 477 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 478 | return SemaRef.Context.getTypeDeclType(Enum); |
| 479 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 480 | |
| 481 | /// \brief Build a new elaborated type. |
| 482 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 483 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 484 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | |
| 486 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 487 | /// |
| 488 | /// By default, performs semantic analysis when building the typeof type. |
| 489 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 490 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 491 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | /// |
| 494 | /// By default, builds a new TypeOfType with the given underlying type. |
| 495 | QualType RebuildTypeOfType(QualType Underlying); |
| 496 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 498 | /// |
| 499 | /// By default, performs semantic analysis when building the decltype type. |
| 500 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 501 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 503 | /// \brief Build a new template specialization type. |
| 504 | /// |
| 505 | /// By default, performs semantic analysis when building the template |
| 506 | /// specialization type. Subclasses may override this routine to provide |
| 507 | /// different behavior. |
| 508 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 509 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 510 | const TemplateArgumentListInfo &Args); |
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 qualified name type. |
| 513 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | /// By default, builds a new QualifiedNameType type from the |
| 515 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 516 | /// this routine to provide different behavior. |
| 517 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 518 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 520 | |
| 521 | /// \brief Build a new typename type that refers to a template-id. |
| 522 | /// |
| 523 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 525 | /// different behavior. |
| 526 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 527 | if (NNS->isDependent()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 529 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | |
| 534 | /// \brief Build a new typename type that refers to an identifier. |
| 535 | /// |
| 536 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 538 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 540 | const IdentifierInfo *Id, |
| 541 | SourceRange SR) { |
| 542 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 545 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 546 | /// identifier that names the next step in the nested-name-specifier. |
| 547 | /// |
| 548 | /// By default, performs semantic analysis when building the new |
| 549 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 550 | /// different behavior. |
| 551 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 552 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 553 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 554 | QualType ObjectType, |
| 555 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 556 | |
| 557 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 558 | /// namespace named in the next step in the nested-name-specifier. |
| 559 | /// |
| 560 | /// By default, performs semantic analysis when building the new |
| 561 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 562 | /// different behavior. |
| 563 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 564 | SourceRange Range, |
| 565 | NamespaceDecl *NS); |
| 566 | |
| 567 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 568 | /// type named in the next step in the nested-name-specifier. |
| 569 | /// |
| 570 | /// By default, performs semantic analysis when building the new |
| 571 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 572 | /// different behavior. |
| 573 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 574 | SourceRange Range, |
| 575 | bool TemplateKW, |
| 576 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 577 | |
| 578 | /// \brief Build a new template name given a nested name specifier, a flag |
| 579 | /// indicating whether the "template" keyword was provided, and the template |
| 580 | /// that the template name refers to. |
| 581 | /// |
| 582 | /// By default, builds the new template name directly. Subclasses may override |
| 583 | /// this routine to provide different behavior. |
| 584 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 585 | bool TemplateKW, |
| 586 | TemplateDecl *Template); |
| 587 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 588 | /// \brief Build a new template name given a nested name specifier and the |
| 589 | /// name that is referred to as a template. |
| 590 | /// |
| 591 | /// By default, performs semantic analysis to determine whether the name can |
| 592 | /// be resolved to a specific template, then builds the appropriate kind of |
| 593 | /// template name. Subclasses may override this routine to provide different |
| 594 | /// behavior. |
| 595 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 596 | const IdentifierInfo &II, |
| 597 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 599 | /// \brief Build a new template name given a nested name specifier and the |
| 600 | /// overloaded operator name that is referred to as a template. |
| 601 | /// |
| 602 | /// By default, performs semantic analysis to determine whether the name can |
| 603 | /// be resolved to a specific template, then builds the appropriate kind of |
| 604 | /// template name. Subclasses may override this routine to provide different |
| 605 | /// behavior. |
| 606 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 607 | OverloadedOperatorKind Operator, |
| 608 | QualType ObjectType); |
| 609 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 610 | /// \brief Build a new compound statement. |
| 611 | /// |
| 612 | /// By default, performs semantic analysis to build the new statement. |
| 613 | /// Subclasses may override this routine to provide different behavior. |
| 614 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 615 | MultiStmtArg Statements, |
| 616 | SourceLocation RBraceLoc, |
| 617 | bool IsStmtExpr) { |
| 618 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 619 | IsStmtExpr); |
| 620 | } |
| 621 | |
| 622 | /// \brief Build a new case statement. |
| 623 | /// |
| 624 | /// By default, performs semantic analysis to build the new statement. |
| 625 | /// Subclasses may override this routine to provide different behavior. |
| 626 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 627 | ExprArg LHS, |
| 628 | SourceLocation EllipsisLoc, |
| 629 | ExprArg RHS, |
| 630 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 632 | ColonLoc); |
| 633 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 635 | /// \brief Attach the body to a new case statement. |
| 636 | /// |
| 637 | /// By default, performs semantic analysis to build the new statement. |
| 638 | /// Subclasses may override this routine to provide different behavior. |
| 639 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 640 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 641 | return move(S); |
| 642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 644 | /// \brief Build a new default statement. |
| 645 | /// |
| 646 | /// By default, performs semantic analysis to build the new statement. |
| 647 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 648 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 649 | SourceLocation ColonLoc, |
| 650 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 652 | /*CurScope=*/0); |
| 653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 655 | /// \brief Build a new label statement. |
| 656 | /// |
| 657 | /// By default, performs semantic analysis to build the new statement. |
| 658 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 660 | IdentifierInfo *Id, |
| 661 | SourceLocation ColonLoc, |
| 662 | StmtArg SubStmt) { |
| 663 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 664 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 666 | /// \brief Build a new "if" statement. |
| 667 | /// |
| 668 | /// By default, performs semantic analysis to build the new statement. |
| 669 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 670 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 671 | VarDecl *CondVar, StmtArg Then, |
| 672 | SourceLocation ElseLoc, StmtArg Else) { |
| 673 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 674 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 675 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 677 | /// \brief Start building a new switch statement. |
| 678 | /// |
| 679 | /// By default, performs semantic analysis to build the new statement. |
| 680 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 681 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 682 | VarDecl *CondVar) { |
| 683 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 684 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 686 | /// \brief Attach the body to the switch statement. |
| 687 | /// |
| 688 | /// By default, performs semantic analysis to build the new statement. |
| 689 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 691 | StmtArg Switch, StmtArg Body) { |
| 692 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 693 | move(Body)); |
| 694 | } |
| 695 | |
| 696 | /// \brief Build a new while statement. |
| 697 | /// |
| 698 | /// By default, performs semantic analysis to build the new statement. |
| 699 | /// Subclasses may override this routine to provide different behavior. |
| 700 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 701 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 702 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 703 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 704 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 705 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 706 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 708 | /// \brief Build a new do-while statement. |
| 709 | /// |
| 710 | /// By default, performs semantic analysis to build the new statement. |
| 711 | /// Subclasses may override this routine to provide different behavior. |
| 712 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 713 | SourceLocation WhileLoc, |
| 714 | SourceLocation LParenLoc, |
| 715 | ExprArg Cond, |
| 716 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 718 | move(Cond), RParenLoc); |
| 719 | } |
| 720 | |
| 721 | /// \brief Build a new for statement. |
| 722 | /// |
| 723 | /// By default, performs semantic analysis to build the new statement. |
| 724 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 726 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 727 | StmtArg Init, Sema::FullExprArg Cond, |
| 728 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 729 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 730 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 731 | DeclPtrTy::make(CondVar), |
| 732 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | /// \brief Build a new goto statement. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis to build the new statement. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
| 739 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 740 | SourceLocation LabelLoc, |
| 741 | LabelStmt *Label) { |
| 742 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 743 | } |
| 744 | |
| 745 | /// \brief Build a new indirect goto statement. |
| 746 | /// |
| 747 | /// By default, performs semantic analysis to build the new statement. |
| 748 | /// Subclasses may override this routine to provide different behavior. |
| 749 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 750 | SourceLocation StarLoc, |
| 751 | ExprArg Target) { |
| 752 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 753 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 755 | /// \brief Build a new return statement. |
| 756 | /// |
| 757 | /// By default, performs semantic analysis to build the new statement. |
| 758 | /// Subclasses may override this routine to provide different behavior. |
| 759 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 760 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 762 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 763 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 765 | /// \brief Build a new declaration statement. |
| 766 | /// |
| 767 | /// By default, performs semantic analysis to build the new statement. |
| 768 | /// Subclasses may override this routine to provide different behavior. |
| 769 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 771 | SourceLocation EndLoc) { |
| 772 | return getSema().Owned( |
| 773 | new (getSema().Context) DeclStmt( |
| 774 | DeclGroupRef::Create(getSema().Context, |
| 775 | Decls, NumDecls), |
| 776 | StartLoc, EndLoc)); |
| 777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 779 | /// \brief Build a new C++ exception declaration. |
| 780 | /// |
| 781 | /// By default, performs semantic analysis to build the new decaration. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 784 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 785 | IdentifierInfo *Name, |
| 786 | SourceLocation Loc, |
| 787 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 789 | TypeRange); |
| 790 | } |
| 791 | |
| 792 | /// \brief Build a new C++ catch statement. |
| 793 | /// |
| 794 | /// By default, performs semantic analysis to build the new statement. |
| 795 | /// Subclasses may override this routine to provide different behavior. |
| 796 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 797 | VarDecl *ExceptionDecl, |
| 798 | StmtArg Handler) { |
| 799 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | Handler.takeAs<Stmt>())); |
| 802 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 804 | /// \brief Build a new C++ try statement. |
| 805 | /// |
| 806 | /// By default, performs semantic analysis to build the new statement. |
| 807 | /// Subclasses may override this routine to provide different behavior. |
| 808 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 809 | StmtArg TryBlock, |
| 810 | MultiStmtArg Handlers) { |
| 811 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 813 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 814 | /// \brief Build a new expression that references a declaration. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis to build the new expression. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 818 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 819 | LookupResult &R, |
| 820 | bool RequiresADL) { |
| 821 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 822 | } |
| 823 | |
| 824 | |
| 825 | /// \brief Build a new expression that references a declaration. |
| 826 | /// |
| 827 | /// By default, performs semantic analysis to build the new expression. |
| 828 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 829 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 830 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 831 | ValueDecl *VD, SourceLocation Loc, |
| 832 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 833 | CXXScopeSpec SS; |
| 834 | SS.setScopeRep(Qualifier); |
| 835 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 836 | |
| 837 | // FIXME: loses template args. |
| 838 | |
| 839 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 840 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 842 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 844 | /// By default, performs semantic analysis to build the new expression. |
| 845 | /// Subclasses may override this routine to provide different behavior. |
| 846 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 847 | SourceLocation RParen) { |
| 848 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 849 | } |
| 850 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 851 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 853 | /// By default, performs semantic analysis to build the new expression. |
| 854 | /// Subclasses may override this routine to provide different behavior. |
| 855 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 856 | SourceLocation OperatorLoc, |
| 857 | bool isArrow, |
| 858 | SourceLocation DestroyedTypeLoc, |
| 859 | QualType DestroyedType, |
| 860 | NestedNameSpecifier *Qualifier, |
| 861 | SourceRange QualifierRange) { |
| 862 | CXXScopeSpec SS; |
| 863 | if (Qualifier) { |
| 864 | SS.setRange(QualifierRange); |
| 865 | SS.setScopeRep(Qualifier); |
| 866 | } |
| 867 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 868 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 869 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | DeclarationName Name |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 871 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 872 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 873 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 874 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 875 | OperatorLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 876 | SS, /*FIXME: FirstQualifier*/ 0, |
| 877 | Name, DestroyedTypeLoc, |
| 878 | /*TemplateArgs*/ 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 881 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 883 | /// By default, performs semantic analysis to build the new expression. |
| 884 | /// Subclasses may override this routine to provide different behavior. |
| 885 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 886 | UnaryOperator::Opcode Opc, |
| 887 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 888 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 889 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 893 | /// By default, performs semantic analysis to build the new expression. |
| 894 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 895 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 896 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 897 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 898 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 901 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 902 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 903 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 904 | /// By default, performs semantic analysis to build the new expression. |
| 905 | /// Subclasses may override this routine to provide different behavior. |
| 906 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 907 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 909 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 910 | OpLoc, isSizeOf, R); |
| 911 | if (Result.isInvalid()) |
| 912 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 914 | SubExpr.release(); |
| 915 | return move(Result); |
| 916 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 918 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | /// By default, performs semantic analysis to build the new expression. |
| 921 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 922 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 923 | SourceLocation LBracketLoc, |
| 924 | ExprArg RHS, |
| 925 | SourceLocation RBracketLoc) { |
| 926 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | RBracketLoc); |
| 929 | } |
| 930 | |
| 931 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 932 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 933 | /// By default, performs semantic analysis to build the new expression. |
| 934 | /// Subclasses may override this routine to provide different behavior. |
| 935 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 936 | MultiExprArg Args, |
| 937 | SourceLocation *CommaLocs, |
| 938 | SourceLocation RParenLoc) { |
| 939 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 940 | move(Args), CommaLocs, RParenLoc); |
| 941 | } |
| 942 | |
| 943 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | /// By default, performs semantic analysis to build the new expression. |
| 946 | /// Subclasses may override this routine to provide different behavior. |
| 947 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 949 | NestedNameSpecifier *Qualifier, |
| 950 | SourceRange QualifierRange, |
| 951 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 952 | ValueDecl *Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 953 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 954 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 955 | if (!Member->getDeclName()) { |
| 956 | // We have a reference to an unnamed field. |
| 957 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 959 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 960 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 961 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 962 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 964 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 965 | Member, MemberLoc, |
| 966 | cast<FieldDecl>(Member)->getType()); |
| 967 | return getSema().Owned(ME); |
| 968 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 970 | CXXScopeSpec SS; |
| 971 | if (Qualifier) { |
| 972 | SS.setRange(QualifierRange); |
| 973 | SS.setScopeRep(Qualifier); |
| 974 | } |
| 975 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 976 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 977 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 978 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 979 | Sema::LookupMemberName); |
| 980 | R.addDecl(Member); |
| 981 | R.resolveKind(); |
| 982 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 983 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 984 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 985 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 986 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 989 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | /// By default, performs semantic analysis to build the new expression. |
| 992 | /// Subclasses may override this routine to provide different behavior. |
| 993 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 994 | BinaryOperator::Opcode Opc, |
| 995 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 996 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 997 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1002 | /// By default, performs semantic analysis to build the new expression. |
| 1003 | /// Subclasses may override this routine to provide different behavior. |
| 1004 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1005 | SourceLocation QuestionLoc, |
| 1006 | ExprArg LHS, |
| 1007 | SourceLocation ColonLoc, |
| 1008 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | move(LHS), move(RHS)); |
| 1011 | } |
| 1012 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1013 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1015 | /// By default, performs semantic analysis to build the new expression. |
| 1016 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1017 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1018 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1019 | SourceLocation RParenLoc, |
| 1020 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame^] | 1021 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1022 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1027 | /// By default, performs semantic analysis to build the new expression. |
| 1028 | /// Subclasses may override this routine to provide different behavior. |
| 1029 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1030 | QualType T, |
| 1031 | SourceLocation RParenLoc, |
| 1032 | ExprArg Init) { |
| 1033 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1034 | RParenLoc, move(Init)); |
| 1035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1042 | SourceLocation OpLoc, |
| 1043 | SourceLocation AccessorLoc, |
| 1044 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1045 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1046 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1047 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1048 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1049 | OpLoc, /*IsArrow*/ false, |
| 1050 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1051 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1052 | AccessorLoc, |
| 1053 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1056 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | /// By default, performs semantic analysis to build the new expression. |
| 1059 | /// Subclasses may override this routine to provide different behavior. |
| 1060 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1061 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1062 | SourceLocation RBraceLoc, |
| 1063 | QualType ResultTy) { |
| 1064 | OwningExprResult Result |
| 1065 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1066 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1067 | return move(Result); |
| 1068 | |
| 1069 | // Patch in the result type we were given, which may have been computed |
| 1070 | // when the initial InitListExpr was built. |
| 1071 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1072 | ILE->setType(ResultTy); |
| 1073 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1074 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | /// By default, performs semantic analysis to build the new expression. |
| 1079 | /// Subclasses may override this routine to provide different behavior. |
| 1080 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1081 | MultiExprArg ArrayExprs, |
| 1082 | SourceLocation EqualOrColonLoc, |
| 1083 | bool GNUSyntax, |
| 1084 | ExprArg Init) { |
| 1085 | OwningExprResult Result |
| 1086 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1087 | move(Init)); |
| 1088 | if (Result.isInvalid()) |
| 1089 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1091 | ArrayExprs.release(); |
| 1092 | return move(Result); |
| 1093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1095 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | /// By default, builds the implicit value initialization without performing |
| 1098 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1099 | /// different behavior. |
| 1100 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1101 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1102 | } |
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 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1106 | /// By default, performs semantic analysis to build the new expression. |
| 1107 | /// Subclasses may override this routine to provide different behavior. |
| 1108 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1109 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1110 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1111 | RParenLoc); |
| 1112 | } |
| 1113 | |
| 1114 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1116 | /// By default, performs semantic analysis to build the new expression. |
| 1117 | /// Subclasses may override this routine to provide different behavior. |
| 1118 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1119 | MultiExprArg SubExprs, |
| 1120 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1121 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1122 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | /// |
| 1127 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// rather than attempting to map the label statement itself. |
| 1129 | /// Subclasses may override this routine to provide different behavior. |
| 1130 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1131 | SourceLocation LabelLoc, |
| 1132 | LabelStmt *Label) { |
| 1133 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1136 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | /// By default, performs semantic analysis to build the new expression. |
| 1139 | /// Subclasses may override this routine to provide different behavior. |
| 1140 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1141 | StmtArg SubStmt, |
| 1142 | SourceLocation RParenLoc) { |
| 1143 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1146 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1147 | /// |
| 1148 | /// By default, performs semantic analysis to build the new expression. |
| 1149 | /// Subclasses may override this routine to provide different behavior. |
| 1150 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1151 | QualType T1, QualType T2, |
| 1152 | SourceLocation RParenLoc) { |
| 1153 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1154 | T1.getAsOpaquePtr(), |
| 1155 | T2.getAsOpaquePtr(), |
| 1156 | RParenLoc); |
| 1157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1159 | /// \brief Build a new __builtin_choose_expr expression. |
| 1160 | /// |
| 1161 | /// By default, performs semantic analysis to build the new expression. |
| 1162 | /// Subclasses may override this routine to provide different behavior. |
| 1163 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1164 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1165 | SourceLocation RParenLoc) { |
| 1166 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1167 | move(Cond), move(LHS), move(RHS), |
| 1168 | RParenLoc); |
| 1169 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1171 | /// \brief Build a new overloaded operator call expression. |
| 1172 | /// |
| 1173 | /// By default, performs semantic analysis to build the new expression. |
| 1174 | /// The semantic analysis provides the behavior of template instantiation, |
| 1175 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1177 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1178 | /// provide different behavior. |
| 1179 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1180 | SourceLocation OpLoc, |
| 1181 | ExprArg Callee, |
| 1182 | ExprArg First, |
| 1183 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1184 | |
| 1185 | /// \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] | 1186 | /// reinterpret_cast. |
| 1187 | /// |
| 1188 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1190 | /// Subclasses may override this routine to provide different behavior. |
| 1191 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1192 | Stmt::StmtClass Class, |
| 1193 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1194 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1195 | SourceLocation RAngleLoc, |
| 1196 | SourceLocation LParenLoc, |
| 1197 | ExprArg SubExpr, |
| 1198 | SourceLocation RParenLoc) { |
| 1199 | switch (Class) { |
| 1200 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1201 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1202 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1203 | move(SubExpr), RParenLoc); |
| 1204 | |
| 1205 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1206 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1210 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1211 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | RAngleLoc, LParenLoc, |
| 1213 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1214 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1217 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | default: |
| 1222 | assert(false && "Invalid C++ named cast"); |
| 1223 | break; |
| 1224 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1226 | return getSema().ExprError(); |
| 1227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1229 | /// \brief Build a new C++ static_cast expression. |
| 1230 | /// |
| 1231 | /// By default, performs semantic analysis to build the new expression. |
| 1232 | /// Subclasses may override this routine to provide different behavior. |
| 1233 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1234 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1235 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | SourceLocation RAngleLoc, |
| 1237 | SourceLocation LParenLoc, |
| 1238 | ExprArg SubExpr, |
| 1239 | SourceLocation RParenLoc) { |
| 1240 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1241 | LAngleLoc, |
| 1242 | TInfo->getType().getAsOpaquePtr(), |
| 1243 | RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | LParenLoc, move(SubExpr), RParenLoc); |
| 1245 | } |
| 1246 | |
| 1247 | /// \brief Build a new C++ dynamic_cast expression. |
| 1248 | /// |
| 1249 | /// By default, performs semantic analysis to build the new expression. |
| 1250 | /// Subclasses may override this routine to provide different behavior. |
| 1251 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1252 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1253 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1254 | SourceLocation RAngleLoc, |
| 1255 | SourceLocation LParenLoc, |
| 1256 | ExprArg SubExpr, |
| 1257 | SourceLocation RParenLoc) { |
| 1258 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1259 | LAngleLoc, |
| 1260 | TInfo->getType().getAsOpaquePtr(), |
| 1261 | RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1262 | LParenLoc, move(SubExpr), RParenLoc); |
| 1263 | } |
| 1264 | |
| 1265 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1266 | /// |
| 1267 | /// By default, performs semantic analysis to build the new expression. |
| 1268 | /// Subclasses may override this routine to provide different behavior. |
| 1269 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1270 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1271 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1272 | SourceLocation RAngleLoc, |
| 1273 | SourceLocation LParenLoc, |
| 1274 | ExprArg SubExpr, |
| 1275 | SourceLocation RParenLoc) { |
| 1276 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1277 | LAngleLoc, |
| 1278 | TInfo->getType().getAsOpaquePtr(), |
| 1279 | RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1280 | LParenLoc, move(SubExpr), RParenLoc); |
| 1281 | } |
| 1282 | |
| 1283 | /// \brief Build a new C++ const_cast expression. |
| 1284 | /// |
| 1285 | /// By default, performs semantic analysis to build the new expression. |
| 1286 | /// Subclasses may override this routine to provide different behavior. |
| 1287 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1288 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1289 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1290 | SourceLocation RAngleLoc, |
| 1291 | SourceLocation LParenLoc, |
| 1292 | ExprArg SubExpr, |
| 1293 | SourceLocation RParenLoc) { |
| 1294 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1295 | LAngleLoc, |
| 1296 | TInfo->getType().getAsOpaquePtr(), |
| 1297 | RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1298 | LParenLoc, move(SubExpr), RParenLoc); |
| 1299 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1300 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1301 | /// \brief Build a new C++ functional-style cast expression. |
| 1302 | /// |
| 1303 | /// By default, performs semantic analysis to build the new expression. |
| 1304 | /// Subclasses may override this routine to provide different behavior. |
| 1305 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1306 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | SourceLocation LParenLoc, |
| 1308 | ExprArg SubExpr, |
| 1309 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1310 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1312 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1314 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | RParenLoc); |
| 1317 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | /// \brief Build a new C++ typeid(type) expression. |
| 1320 | /// |
| 1321 | /// By default, performs semantic analysis to build the new expression. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
| 1323 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1324 | SourceLocation LParenLoc, |
| 1325 | QualType T, |
| 1326 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1328 | T.getAsOpaquePtr(), RParenLoc); |
| 1329 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | /// \brief Build a new C++ typeid(expr) expression. |
| 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new expression. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1336 | SourceLocation LParenLoc, |
| 1337 | ExprArg Operand, |
| 1338 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1339 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1340 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1341 | RParenLoc); |
| 1342 | if (Result.isInvalid()) |
| 1343 | return getSema().ExprError(); |
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 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1346 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | /// \brief Build a new C++ "this" expression. |
| 1350 | /// |
| 1351 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1355 | QualType ThisType, |
| 1356 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1357 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1358 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1359 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | /// \brief Build a new C++ throw expression. |
| 1363 | /// |
| 1364 | /// By default, performs semantic analysis to build the new expression. |
| 1365 | /// Subclasses may override this routine to provide different behavior. |
| 1366 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1367 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1368 | } |
| 1369 | |
| 1370 | /// \brief Build a new C++ default-argument expression. |
| 1371 | /// |
| 1372 | /// By default, builds a new default-argument expression, which does not |
| 1373 | /// require any semantic analysis. Subclasses may override this routine to |
| 1374 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1375 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1376 | ParmVarDecl *Param) { |
| 1377 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1378 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /// \brief Build a new C++ zero-initialization expression. |
| 1382 | /// |
| 1383 | /// By default, performs semantic analysis to build the new expression. |
| 1384 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | SourceLocation LParenLoc, |
| 1387 | QualType T, |
| 1388 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1390 | T.getAsOpaquePtr(), LParenLoc, |
| 1391 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | 0, RParenLoc); |
| 1393 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1395 | /// \brief Build a new C++ "new" expression. |
| 1396 | /// |
| 1397 | /// By default, performs semantic analysis to build the new expression. |
| 1398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1400 | bool UseGlobal, |
| 1401 | SourceLocation PlacementLParen, |
| 1402 | MultiExprArg PlacementArgs, |
| 1403 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | QualType AllocType, |
| 1406 | SourceLocation TypeLoc, |
| 1407 | SourceRange TypeRange, |
| 1408 | ExprArg ArraySize, |
| 1409 | SourceLocation ConstructorLParen, |
| 1410 | MultiExprArg ConstructorArgs, |
| 1411 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1413 | PlacementLParen, |
| 1414 | move(PlacementArgs), |
| 1415 | PlacementRParen, |
| 1416 | ParenTypeId, |
| 1417 | AllocType, |
| 1418 | TypeLoc, |
| 1419 | TypeRange, |
| 1420 | move(ArraySize), |
| 1421 | ConstructorLParen, |
| 1422 | move(ConstructorArgs), |
| 1423 | ConstructorRParen); |
| 1424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1426 | /// \brief Build a new C++ "delete" expression. |
| 1427 | /// |
| 1428 | /// By default, performs semantic analysis to build the new expression. |
| 1429 | /// Subclasses may override this routine to provide different behavior. |
| 1430 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1431 | bool IsGlobalDelete, |
| 1432 | bool IsArrayForm, |
| 1433 | ExprArg Operand) { |
| 1434 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1435 | move(Operand)); |
| 1436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | /// \brief Build a new unary type trait expression. |
| 1439 | /// |
| 1440 | /// By default, performs semantic analysis to build the new expression. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
| 1442 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1443 | SourceLocation StartLoc, |
| 1444 | SourceLocation LParenLoc, |
| 1445 | QualType T, |
| 1446 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | T.getAsOpaquePtr(), RParenLoc); |
| 1449 | } |
| 1450 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1451 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1452 | /// expression. |
| 1453 | /// |
| 1454 | /// By default, performs semantic analysis to build the new expression. |
| 1455 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1456 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | SourceRange QualifierRange, |
| 1458 | DeclarationName Name, |
| 1459 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1460 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1461 | CXXScopeSpec SS; |
| 1462 | SS.setRange(QualifierRange); |
| 1463 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1464 | |
| 1465 | if (TemplateArgs) |
| 1466 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1467 | *TemplateArgs); |
| 1468 | |
| 1469 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /// \brief Build a new template-id expression. |
| 1473 | /// |
| 1474 | /// By default, performs semantic analysis to build the new expression. |
| 1475 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1476 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1477 | LookupResult &R, |
| 1478 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1479 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1480 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /// \brief Build a new object-construction expression. |
| 1484 | /// |
| 1485 | /// By default, performs semantic analysis to build the new expression. |
| 1486 | /// Subclasses may override this routine to provide different behavior. |
| 1487 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1488 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | CXXConstructorDecl *Constructor, |
| 1490 | bool IsElidable, |
| 1491 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1492 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1493 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1494 | ConvertedArgs)) |
| 1495 | return getSema().ExprError(); |
| 1496 | |
| 1497 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1498 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /// \brief Build a new object-construction expression. |
| 1502 | /// |
| 1503 | /// By default, performs semantic analysis to build the new expression. |
| 1504 | /// Subclasses may override this routine to provide different behavior. |
| 1505 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1506 | QualType T, |
| 1507 | SourceLocation LParenLoc, |
| 1508 | MultiExprArg Args, |
| 1509 | SourceLocation *Commas, |
| 1510 | SourceLocation RParenLoc) { |
| 1511 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1512 | T.getAsOpaquePtr(), |
| 1513 | LParenLoc, |
| 1514 | move(Args), |
| 1515 | Commas, |
| 1516 | RParenLoc); |
| 1517 | } |
| 1518 | |
| 1519 | /// \brief Build a new object-construction expression. |
| 1520 | /// |
| 1521 | /// By default, performs semantic analysis to build the new expression. |
| 1522 | /// Subclasses may override this routine to provide different behavior. |
| 1523 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1524 | QualType T, |
| 1525 | SourceLocation LParenLoc, |
| 1526 | MultiExprArg Args, |
| 1527 | SourceLocation *Commas, |
| 1528 | SourceLocation RParenLoc) { |
| 1529 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1530 | /*FIXME*/LParenLoc), |
| 1531 | T.getAsOpaquePtr(), |
| 1532 | LParenLoc, |
| 1533 | move(Args), |
| 1534 | Commas, |
| 1535 | RParenLoc); |
| 1536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1537 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1538 | /// \brief Build a new member reference expression. |
| 1539 | /// |
| 1540 | /// By default, performs semantic analysis to build the new expression. |
| 1541 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1542 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1543 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | bool IsArrow, |
| 1545 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1546 | NestedNameSpecifier *Qualifier, |
| 1547 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1548 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1549 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1550 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1551 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1552 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1553 | SS.setRange(QualifierRange); |
| 1554 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1555 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1556 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1557 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1558 | SS, FirstQualifierInScope, |
| 1559 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1562 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1563 | /// |
| 1564 | /// By default, performs semantic analysis to build the new expression. |
| 1565 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1566 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1567 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1568 | SourceLocation OperatorLoc, |
| 1569 | bool IsArrow, |
| 1570 | NestedNameSpecifier *Qualifier, |
| 1571 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1572 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1573 | LookupResult &R, |
| 1574 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1575 | CXXScopeSpec SS; |
| 1576 | SS.setRange(QualifierRange); |
| 1577 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1579 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1580 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1581 | SS, FirstQualifierInScope, |
| 1582 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1583 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1584 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1585 | /// \brief Build a new Objective-C @encode expression. |
| 1586 | /// |
| 1587 | /// By default, performs semantic analysis to build the new expression. |
| 1588 | /// Subclasses may override this routine to provide different behavior. |
| 1589 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1590 | QualType T, |
| 1591 | SourceLocation RParenLoc) { |
| 1592 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1593 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1594 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | |
| 1596 | /// \brief Build a new Objective-C protocol expression. |
| 1597 | /// |
| 1598 | /// By default, performs semantic analysis to build the new expression. |
| 1599 | /// Subclasses may override this routine to provide different behavior. |
| 1600 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1601 | SourceLocation AtLoc, |
| 1602 | SourceLocation ProtoLoc, |
| 1603 | SourceLocation LParenLoc, |
| 1604 | SourceLocation RParenLoc) { |
| 1605 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1606 | Protocol->getIdentifier(), |
| 1607 | AtLoc, |
| 1608 | ProtoLoc, |
| 1609 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1612 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1613 | /// \brief Build a new shuffle vector expression. |
| 1614 | /// |
| 1615 | /// By default, performs semantic analysis to build the new expression. |
| 1616 | /// Subclasses may override this routine to provide different behavior. |
| 1617 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1618 | MultiExprArg SubExprs, |
| 1619 | SourceLocation RParenLoc) { |
| 1620 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1621 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1623 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1624 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1625 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1626 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1627 | // Build a reference to the __builtin_shufflevector builtin |
| 1628 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1629 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1630 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1631 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1632 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | |
| 1634 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | unsigned NumSubExprs = SubExprs.size(); |
| 1636 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1637 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1638 | Subs, NumSubExprs, |
| 1639 | Builtin->getResultType(), |
| 1640 | RParenLoc); |
| 1641 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1642 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | // Type-check the __builtin_shufflevector expression. |
| 1644 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1645 | if (Result.isInvalid()) |
| 1646 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1651 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1653 | template<typename Derived> |
| 1654 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1655 | if (!S) |
| 1656 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1658 | switch (S->getStmtClass()) { |
| 1659 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1660 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1661 | // Transform individual statement nodes |
| 1662 | #define STMT(Node, Parent) \ |
| 1663 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1664 | #define EXPR(Node, Parent) |
| 1665 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1667 | // Transform expressions by calling TransformExpr. |
| 1668 | #define STMT(Node, Parent) |
| 1669 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1670 | #include "clang/AST/StmtNodes.def" |
| 1671 | { |
| 1672 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1673 | if (E.isInvalid()) |
| 1674 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1676 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1680 | return SemaRef.Owned(S->Retain()); |
| 1681 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
| 1683 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1684 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1685 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | if (!E) |
| 1687 | return SemaRef.Owned(E); |
| 1688 | |
| 1689 | switch (E->getStmtClass()) { |
| 1690 | case Stmt::NoStmtClass: break; |
| 1691 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1692 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1693 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1694 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1697 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1701 | NestedNameSpecifier * |
| 1702 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1703 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1704 | QualType ObjectType, |
| 1705 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1706 | if (!NNS) |
| 1707 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1709 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1710 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1711 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1712 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1713 | ObjectType, |
| 1714 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1715 | if (!Prefix) |
| 1716 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | |
| 1718 | // 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] | 1719 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1720 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1721 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1723 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1724 | switch (NNS->getKind()) { |
| 1725 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1726 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1727 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1728 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1729 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1730 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | |
| 1732 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1733 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1734 | ObjectType, |
| 1735 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1737 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1738 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1739 | = cast_or_null<NamespaceDecl>( |
| 1740 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1742 | Prefix == NNS->getPrefix() && |
| 1743 | NS == NNS->getAsNamespace()) |
| 1744 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1745 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1746 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1749 | case NestedNameSpecifier::Global: |
| 1750 | // There is no meaningful transformation that one could perform on the |
| 1751 | // global scope. |
| 1752 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1753 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1754 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1755 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1756 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1757 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1758 | if (T.isNull()) |
| 1759 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1761 | if (!getDerived().AlwaysRebuild() && |
| 1762 | Prefix == NNS->getPrefix() && |
| 1763 | T == QualType(NNS->getAsType(), 0)) |
| 1764 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1765 | |
| 1766 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1767 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1768 | T); |
| 1769 | } |
| 1770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1772 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1778 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1779 | SourceLocation Loc, |
| 1780 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1781 | if (!Name) |
| 1782 | return Name; |
| 1783 | |
| 1784 | switch (Name.getNameKind()) { |
| 1785 | case DeclarationName::Identifier: |
| 1786 | case DeclarationName::ObjCZeroArgSelector: |
| 1787 | case DeclarationName::ObjCOneArgSelector: |
| 1788 | case DeclarationName::ObjCMultiArgSelector: |
| 1789 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1790 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1791 | case DeclarationName::CXXUsingDirective: |
| 1792 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1794 | case DeclarationName::CXXConstructorName: |
| 1795 | case DeclarationName::CXXDestructorName: |
| 1796 | case DeclarationName::CXXConversionFunctionName: { |
| 1797 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1798 | QualType T; |
| 1799 | if (!ObjectType.isNull() && |
| 1800 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1801 | TemplateSpecializationType *SpecType |
| 1802 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1803 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1804 | } else |
| 1805 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | if (T.isNull()) |
| 1807 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1809 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1811 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1815 | return DeclarationName(); |
| 1816 | } |
| 1817 | |
| 1818 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1819 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1820 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1821 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1822 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1824 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1825 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1826 | if (!NNS) |
| 1827 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1828 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1829 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1830 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1831 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1832 | if (!TransTemplate) |
| 1833 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1835 | if (!getDerived().AlwaysRebuild() && |
| 1836 | NNS == QTN->getQualifier() && |
| 1837 | TransTemplate == Template) |
| 1838 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1840 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1841 | TransTemplate); |
| 1842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1844 | // These should be getting filtered out before they make it into the AST. |
| 1845 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1846 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1848 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1851 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1852 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1855 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1856 | NNS == DTN->getQualifier() && |
| 1857 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1858 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1860 | if (DTN->isIdentifier()) |
| 1861 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1862 | ObjectType); |
| 1863 | |
| 1864 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1865 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1869 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1870 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1871 | if (!TransTemplate) |
| 1872 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | if (!getDerived().AlwaysRebuild() && |
| 1875 | TransTemplate == Template) |
| 1876 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | return TemplateName(TransTemplate); |
| 1879 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1881 | // These should be getting filtered out before they reach the AST. |
| 1882 | assert(false && "overloaded function decl survived to here"); |
| 1883 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1887 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1888 | const TemplateArgument &Arg, |
| 1889 | TemplateArgumentLoc &Output) { |
| 1890 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1891 | switch (Arg.getKind()) { |
| 1892 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1893 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1894 | break; |
| 1895 | |
| 1896 | case TemplateArgument::Type: |
| 1897 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1898 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1899 | |
| 1900 | break; |
| 1901 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1902 | case TemplateArgument::Template: |
| 1903 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1904 | break; |
| 1905 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1906 | case TemplateArgument::Expression: |
| 1907 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1908 | break; |
| 1909 | |
| 1910 | case TemplateArgument::Declaration: |
| 1911 | case TemplateArgument::Integral: |
| 1912 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1913 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1914 | break; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | template<typename Derived> |
| 1919 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1920 | const TemplateArgumentLoc &Input, |
| 1921 | TemplateArgumentLoc &Output) { |
| 1922 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1923 | switch (Arg.getKind()) { |
| 1924 | case TemplateArgument::Null: |
| 1925 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1926 | Output = Input; |
| 1927 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1928 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1929 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1930 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1931 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1932 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1933 | |
| 1934 | DI = getDerived().TransformType(DI); |
| 1935 | if (!DI) return true; |
| 1936 | |
| 1937 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1938 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1939 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1941 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1942 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1943 | DeclarationName Name; |
| 1944 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1945 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1946 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1947 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1948 | if (!D) return true; |
| 1949 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1950 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1951 | if (SourceExpr) { |
| 1952 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1953 | Action::Unevaluated); |
| 1954 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1955 | if (E.isInvalid()) |
| 1956 | SourceExpr = NULL; |
| 1957 | else { |
| 1958 | SourceExpr = E.takeAs<Expr>(); |
| 1959 | SourceExpr->Retain(); |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1964 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1965 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1966 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1967 | case TemplateArgument::Template: { |
| 1968 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1969 | TemplateName Template |
| 1970 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1971 | if (Template.isNull()) |
| 1972 | return true; |
| 1973 | |
| 1974 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1975 | Input.getTemplateQualifierRange(), |
| 1976 | Input.getTemplateNameLoc()); |
| 1977 | return false; |
| 1978 | } |
| 1979 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1980 | case TemplateArgument::Expression: { |
| 1981 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1982 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1983 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1984 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1985 | Expr *InputExpr = Input.getSourceExpression(); |
| 1986 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1987 | |
| 1988 | Sema::OwningExprResult E |
| 1989 | = getDerived().TransformExpr(InputExpr); |
| 1990 | if (E.isInvalid()) return true; |
| 1991 | |
| 1992 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1993 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1994 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1995 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1996 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1998 | case TemplateArgument::Pack: { |
| 1999 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2000 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2001 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2002 | AEnd = Arg.pack_end(); |
| 2003 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2004 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2005 | // FIXME: preserve source information here when we start |
| 2006 | // caring about parameter packs. |
| 2007 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2008 | TemplateArgumentLoc InputArg; |
| 2009 | TemplateArgumentLoc OutputArg; |
| 2010 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2011 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2012 | return true; |
| 2013 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2014 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2015 | } |
| 2016 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2017 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2018 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2019 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2020 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2021 | } |
| 2022 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2023 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2024 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2025 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2028 | //===----------------------------------------------------------------------===// |
| 2029 | // Type transformation |
| 2030 | //===----------------------------------------------------------------------===// |
| 2031 | |
| 2032 | template<typename Derived> |
| 2033 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2034 | if (getDerived().AlreadyTransformed(T)) |
| 2035 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2036 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2037 | // Temporary workaround. All of these transformations should |
| 2038 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2039 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2040 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2041 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2042 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2043 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2044 | if (!NewDI) |
| 2045 | return QualType(); |
| 2046 | |
| 2047 | return NewDI->getType(); |
| 2048 | } |
| 2049 | |
| 2050 | template<typename Derived> |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2051 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2052 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2053 | return DI; |
| 2054 | |
| 2055 | TypeLocBuilder TLB; |
| 2056 | |
| 2057 | TypeLoc TL = DI->getTypeLoc(); |
| 2058 | TLB.reserve(TL.getFullDataSize()); |
| 2059 | |
| 2060 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2061 | if (Result.isNull()) |
| 2062 | return 0; |
| 2063 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2064 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | template<typename Derived> |
| 2068 | QualType |
| 2069 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2070 | switch (T.getTypeLocClass()) { |
| 2071 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2072 | #define TYPELOC(CLASS, PARENT) \ |
| 2073 | case TypeLoc::CLASS: \ |
| 2074 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2075 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2076 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2077 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2078 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2079 | return QualType(); |
| 2080 | } |
| 2081 | |
| 2082 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2083 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2084 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2085 | /// types). This is the right thing for template instantiation, but |
| 2086 | /// probably not for other clients. |
| 2087 | template<typename Derived> |
| 2088 | QualType |
| 2089 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2090 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2091 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2092 | |
| 2093 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2094 | if (Result.isNull()) |
| 2095 | return QualType(); |
| 2096 | |
| 2097 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2098 | // FIXME: this is the right thing for template instantiation, but |
| 2099 | // probably not for other clients. |
| 2100 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2101 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2103 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2104 | |
| 2105 | TLB.push<QualifiedTypeLoc>(Result); |
| 2106 | |
| 2107 | // No location information to preserve. |
| 2108 | |
| 2109 | return Result; |
| 2110 | } |
| 2111 | |
| 2112 | template <class TyLoc> static inline |
| 2113 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2114 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2115 | NewT.setNameLoc(T.getNameLoc()); |
| 2116 | return T.getType(); |
| 2117 | } |
| 2118 | |
| 2119 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2120 | // the equivalent template version work. |
| 2121 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2122 | QualType PointeeType \ |
| 2123 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2124 | if (PointeeType.isNull()) \ |
| 2125 | return QualType(); \ |
| 2126 | \ |
| 2127 | QualType Result = TL.getType(); \ |
| 2128 | if (getDerived().AlwaysRebuild() || \ |
| 2129 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2130 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2131 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2132 | if (Result.isNull()) \ |
| 2133 | return QualType(); \ |
| 2134 | } \ |
| 2135 | \ |
| 2136 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2137 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2138 | \ |
| 2139 | return Result; \ |
| 2140 | } while(0) |
| 2141 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2142 | template<typename Derived> |
| 2143 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2144 | BuiltinTypeLoc T) { |
| 2145 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2148 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2149 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2150 | ComplexTypeLoc T) { |
| 2151 | // FIXME: recurse? |
| 2152 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2153 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2155 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2156 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2157 | PointerTypeLoc TL) { |
| 2158 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | |
| 2161 | template<typename Derived> |
| 2162 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2163 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2164 | BlockPointerTypeLoc TL) { |
| 2165 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2168 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2169 | /// don't care whether the type itself is an l-value type or an r-value |
| 2170 | /// type; we only care if the type was *written* as an l-value type |
| 2171 | /// or an r-value type. |
| 2172 | template<typename Derived> |
| 2173 | QualType |
| 2174 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2175 | ReferenceTypeLoc TL) { |
| 2176 | const ReferenceType *T = TL.getTypePtr(); |
| 2177 | |
| 2178 | // Note that this works with the pointee-as-written. |
| 2179 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2180 | if (PointeeType.isNull()) |
| 2181 | return QualType(); |
| 2182 | |
| 2183 | QualType Result = TL.getType(); |
| 2184 | if (getDerived().AlwaysRebuild() || |
| 2185 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2186 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2187 | T->isSpelledAsLValue(), |
| 2188 | TL.getSigilLoc()); |
| 2189 | if (Result.isNull()) |
| 2190 | return QualType(); |
| 2191 | } |
| 2192 | |
| 2193 | // r-value references can be rebuilt as l-value references. |
| 2194 | ReferenceTypeLoc NewTL; |
| 2195 | if (isa<LValueReferenceType>(Result)) |
| 2196 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2197 | else |
| 2198 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2199 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2200 | |
| 2201 | return Result; |
| 2202 | } |
| 2203 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | template<typename Derived> |
| 2205 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2206 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2207 | LValueReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2208 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2211 | template<typename Derived> |
| 2212 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2213 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2214 | RValueReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2215 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2216 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2217 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2218 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2219 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2220 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2221 | MemberPointerTypeLoc TL) { |
| 2222 | MemberPointerType *T = TL.getTypePtr(); |
| 2223 | |
| 2224 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2225 | if (PointeeType.isNull()) |
| 2226 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2227 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2228 | // TODO: preserve source information for this. |
| 2229 | QualType ClassType |
| 2230 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2231 | if (ClassType.isNull()) |
| 2232 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2234 | QualType Result = TL.getType(); |
| 2235 | if (getDerived().AlwaysRebuild() || |
| 2236 | PointeeType != T->getPointeeType() || |
| 2237 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2238 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2239 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2240 | if (Result.isNull()) |
| 2241 | return QualType(); |
| 2242 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2243 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2244 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2245 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2246 | |
| 2247 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2250 | template<typename Derived> |
| 2251 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2252 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2253 | ConstantArrayTypeLoc TL) { |
| 2254 | ConstantArrayType *T = TL.getTypePtr(); |
| 2255 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2256 | if (ElementType.isNull()) |
| 2257 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2258 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2259 | QualType Result = TL.getType(); |
| 2260 | if (getDerived().AlwaysRebuild() || |
| 2261 | ElementType != T->getElementType()) { |
| 2262 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2263 | T->getSizeModifier(), |
| 2264 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2265 | T->getIndexTypeCVRQualifiers(), |
| 2266 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2267 | if (Result.isNull()) |
| 2268 | return QualType(); |
| 2269 | } |
| 2270 | |
| 2271 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2272 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2273 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2274 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2275 | Expr *Size = TL.getSizeExpr(); |
| 2276 | if (Size) { |
| 2277 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2278 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2279 | } |
| 2280 | NewTL.setSizeExpr(Size); |
| 2281 | |
| 2282 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2285 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2286 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2287 | TypeLocBuilder &TLB, |
| 2288 | IncompleteArrayTypeLoc TL) { |
| 2289 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2290 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2291 | if (ElementType.isNull()) |
| 2292 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2293 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2294 | QualType Result = TL.getType(); |
| 2295 | if (getDerived().AlwaysRebuild() || |
| 2296 | ElementType != T->getElementType()) { |
| 2297 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2298 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2299 | T->getIndexTypeCVRQualifiers(), |
| 2300 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2301 | if (Result.isNull()) |
| 2302 | return QualType(); |
| 2303 | } |
| 2304 | |
| 2305 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2306 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2307 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2308 | NewTL.setSizeExpr(0); |
| 2309 | |
| 2310 | return Result; |
| 2311 | } |
| 2312 | |
| 2313 | template<typename Derived> |
| 2314 | QualType |
| 2315 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2316 | VariableArrayTypeLoc TL) { |
| 2317 | VariableArrayType *T = TL.getTypePtr(); |
| 2318 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2319 | if (ElementType.isNull()) |
| 2320 | return QualType(); |
| 2321 | |
| 2322 | // Array bounds are not potentially evaluated contexts |
| 2323 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2324 | |
| 2325 | Sema::OwningExprResult SizeResult |
| 2326 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2327 | if (SizeResult.isInvalid()) |
| 2328 | return QualType(); |
| 2329 | |
| 2330 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2331 | |
| 2332 | QualType Result = TL.getType(); |
| 2333 | if (getDerived().AlwaysRebuild() || |
| 2334 | ElementType != T->getElementType() || |
| 2335 | Size != T->getSizeExpr()) { |
| 2336 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2337 | T->getSizeModifier(), |
| 2338 | move(SizeResult), |
| 2339 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2340 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2341 | if (Result.isNull()) |
| 2342 | return QualType(); |
| 2343 | } |
| 2344 | else SizeResult.take(); |
| 2345 | |
| 2346 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2347 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2348 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2349 | NewTL.setSizeExpr(Size); |
| 2350 | |
| 2351 | return Result; |
| 2352 | } |
| 2353 | |
| 2354 | template<typename Derived> |
| 2355 | QualType |
| 2356 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2357 | DependentSizedArrayTypeLoc TL) { |
| 2358 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2359 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2360 | if (ElementType.isNull()) |
| 2361 | return QualType(); |
| 2362 | |
| 2363 | // Array bounds are not potentially evaluated contexts |
| 2364 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2365 | |
| 2366 | Sema::OwningExprResult SizeResult |
| 2367 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2368 | if (SizeResult.isInvalid()) |
| 2369 | return QualType(); |
| 2370 | |
| 2371 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2372 | |
| 2373 | QualType Result = TL.getType(); |
| 2374 | if (getDerived().AlwaysRebuild() || |
| 2375 | ElementType != T->getElementType() || |
| 2376 | Size != T->getSizeExpr()) { |
| 2377 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2378 | T->getSizeModifier(), |
| 2379 | move(SizeResult), |
| 2380 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2381 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2382 | if (Result.isNull()) |
| 2383 | return QualType(); |
| 2384 | } |
| 2385 | else SizeResult.take(); |
| 2386 | |
| 2387 | // We might have any sort of array type now, but fortunately they |
| 2388 | // all have the same location layout. |
| 2389 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2390 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2391 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2392 | NewTL.setSizeExpr(Size); |
| 2393 | |
| 2394 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2396 | |
| 2397 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2398 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2399 | TypeLocBuilder &TLB, |
| 2400 | DependentSizedExtVectorTypeLoc TL) { |
| 2401 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2402 | |
| 2403 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2404 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2405 | if (ElementType.isNull()) |
| 2406 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2407 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2408 | // Vector sizes are not potentially evaluated contexts |
| 2409 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2410 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2411 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2412 | if (Size.isInvalid()) |
| 2413 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2414 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2415 | QualType Result = TL.getType(); |
| 2416 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2417 | ElementType != T->getElementType() || |
| 2418 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2419 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2420 | move(Size), |
| 2421 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2422 | if (Result.isNull()) |
| 2423 | return QualType(); |
| 2424 | } |
| 2425 | else Size.take(); |
| 2426 | |
| 2427 | // Result might be dependent or not. |
| 2428 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2429 | DependentSizedExtVectorTypeLoc NewTL |
| 2430 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2431 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2432 | } else { |
| 2433 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2434 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2435 | } |
| 2436 | |
| 2437 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | |
| 2440 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2441 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2442 | VectorTypeLoc TL) { |
| 2443 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2444 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2445 | if (ElementType.isNull()) |
| 2446 | return QualType(); |
| 2447 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2448 | QualType Result = TL.getType(); |
| 2449 | if (getDerived().AlwaysRebuild() || |
| 2450 | ElementType != T->getElementType()) { |
| 2451 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2452 | if (Result.isNull()) |
| 2453 | return QualType(); |
| 2454 | } |
| 2455 | |
| 2456 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2457 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2458 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2459 | return Result; |
| 2460 | } |
| 2461 | |
| 2462 | template<typename Derived> |
| 2463 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2464 | ExtVectorTypeLoc TL) { |
| 2465 | VectorType *T = TL.getTypePtr(); |
| 2466 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2467 | if (ElementType.isNull()) |
| 2468 | return QualType(); |
| 2469 | |
| 2470 | QualType Result = TL.getType(); |
| 2471 | if (getDerived().AlwaysRebuild() || |
| 2472 | ElementType != T->getElementType()) { |
| 2473 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2474 | T->getNumElements(), |
| 2475 | /*FIXME*/ SourceLocation()); |
| 2476 | if (Result.isNull()) |
| 2477 | return QualType(); |
| 2478 | } |
| 2479 | |
| 2480 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2481 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2482 | |
| 2483 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2484 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2485 | |
| 2486 | template<typename Derived> |
| 2487 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2488 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2489 | FunctionProtoTypeLoc TL) { |
| 2490 | FunctionProtoType *T = TL.getTypePtr(); |
| 2491 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2492 | if (ResultType.isNull()) |
| 2493 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2494 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2495 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2496 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2498 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2499 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2500 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2501 | QualType NewType; |
| 2502 | ParmVarDecl *NewParm; |
| 2503 | |
| 2504 | if (OldParm) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2505 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2506 | assert(OldDI->getType() == T->getArgType(i)); |
| 2507 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2508 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2509 | if (!NewDI) |
| 2510 | return QualType(); |
| 2511 | |
| 2512 | if (NewDI == OldDI) |
| 2513 | NewParm = OldParm; |
| 2514 | else |
| 2515 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2516 | OldParm->getDeclContext(), |
| 2517 | OldParm->getLocation(), |
| 2518 | OldParm->getIdentifier(), |
| 2519 | NewDI->getType(), |
| 2520 | NewDI, |
| 2521 | OldParm->getStorageClass(), |
| 2522 | /* DefArg */ NULL); |
| 2523 | NewType = NewParm->getType(); |
| 2524 | |
| 2525 | // Deal with the possibility that we don't have a parameter |
| 2526 | // declaration for this parameter. |
| 2527 | } else { |
| 2528 | NewParm = 0; |
| 2529 | |
| 2530 | QualType OldType = T->getArgType(i); |
| 2531 | NewType = getDerived().TransformType(OldType); |
| 2532 | if (NewType.isNull()) |
| 2533 | return QualType(); |
| 2534 | } |
| 2535 | |
| 2536 | ParamTypes.push_back(NewType); |
| 2537 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2538 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2539 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2540 | QualType Result = TL.getType(); |
| 2541 | if (getDerived().AlwaysRebuild() || |
| 2542 | ResultType != T->getResultType() || |
| 2543 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2544 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2545 | ParamTypes.data(), |
| 2546 | ParamTypes.size(), |
| 2547 | T->isVariadic(), |
| 2548 | T->getTypeQuals()); |
| 2549 | if (Result.isNull()) |
| 2550 | return QualType(); |
| 2551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2552 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2553 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2554 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2555 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2556 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2557 | NewTL.setArg(i, ParamDecls[i]); |
| 2558 | |
| 2559 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2560 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2561 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2562 | template<typename Derived> |
| 2563 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2564 | TypeLocBuilder &TLB, |
| 2565 | FunctionNoProtoTypeLoc TL) { |
| 2566 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2567 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2568 | if (ResultType.isNull()) |
| 2569 | return QualType(); |
| 2570 | |
| 2571 | QualType Result = TL.getType(); |
| 2572 | if (getDerived().AlwaysRebuild() || |
| 2573 | ResultType != T->getResultType()) |
| 2574 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2575 | |
| 2576 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2577 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2578 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2579 | |
| 2580 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2581 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2582 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2583 | template<typename Derived> QualType |
| 2584 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2585 | UnresolvedUsingTypeLoc TL) { |
| 2586 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2587 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2588 | if (!D) |
| 2589 | return QualType(); |
| 2590 | |
| 2591 | QualType Result = TL.getType(); |
| 2592 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2593 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2594 | if (Result.isNull()) |
| 2595 | return QualType(); |
| 2596 | } |
| 2597 | |
| 2598 | // We might get an arbitrary type spec type back. We should at |
| 2599 | // least always get a type spec type, though. |
| 2600 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2601 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2602 | |
| 2603 | return Result; |
| 2604 | } |
| 2605 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2606 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2607 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2608 | TypedefTypeLoc TL) { |
| 2609 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2610 | TypedefDecl *Typedef |
| 2611 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2612 | if (!Typedef) |
| 2613 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2614 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2615 | QualType Result = TL.getType(); |
| 2616 | if (getDerived().AlwaysRebuild() || |
| 2617 | Typedef != T->getDecl()) { |
| 2618 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2619 | if (Result.isNull()) |
| 2620 | return QualType(); |
| 2621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2622 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2623 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2624 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2625 | |
| 2626 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2628 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2629 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2630 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2631 | TypeOfExprTypeLoc TL) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2632 | // typeof expressions are not potentially evaluated contexts |
| 2633 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2635 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2636 | if (E.isInvalid()) |
| 2637 | return QualType(); |
| 2638 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2639 | QualType Result = TL.getType(); |
| 2640 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2641 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2642 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2643 | if (Result.isNull()) |
| 2644 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2645 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2646 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2647 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2648 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2649 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2650 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2651 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2652 | |
| 2653 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2654 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2655 | |
| 2656 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2657 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2658 | TypeOfTypeLoc TL) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2659 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2660 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2661 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2662 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2663 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2664 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2665 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2666 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2667 | if (Result.isNull()) |
| 2668 | return QualType(); |
| 2669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2671 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2672 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2673 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2674 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2675 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2676 | |
| 2677 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2679 | |
| 2680 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2681 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2682 | DecltypeTypeLoc TL) { |
| 2683 | DecltypeType *T = TL.getTypePtr(); |
| 2684 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2685 | // decltype expressions are not potentially evaluated contexts |
| 2686 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2688 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2689 | if (E.isInvalid()) |
| 2690 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2692 | QualType Result = TL.getType(); |
| 2693 | if (getDerived().AlwaysRebuild() || |
| 2694 | E.get() != T->getUnderlyingExpr()) { |
| 2695 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2696 | if (Result.isNull()) |
| 2697 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2698 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2699 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2700 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2701 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2702 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2703 | |
| 2704 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2708 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2709 | RecordTypeLoc TL) { |
| 2710 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2711 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2712 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2713 | if (!Record) |
| 2714 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2715 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | QualType Result = TL.getType(); |
| 2717 | if (getDerived().AlwaysRebuild() || |
| 2718 | Record != T->getDecl()) { |
| 2719 | Result = getDerived().RebuildRecordType(Record); |
| 2720 | if (Result.isNull()) |
| 2721 | return QualType(); |
| 2722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2723 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2724 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2725 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2726 | |
| 2727 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2728 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2729 | |
| 2730 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2731 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2732 | EnumTypeLoc TL) { |
| 2733 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2734 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2735 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2736 | if (!Enum) |
| 2737 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2738 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2739 | QualType Result = TL.getType(); |
| 2740 | if (getDerived().AlwaysRebuild() || |
| 2741 | Enum != T->getDecl()) { |
| 2742 | Result = getDerived().RebuildEnumType(Enum); |
| 2743 | if (Result.isNull()) |
| 2744 | return QualType(); |
| 2745 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2746 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2747 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2748 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2749 | |
| 2750 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2751 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2752 | |
| 2753 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2755 | ElaboratedTypeLoc TL) { |
| 2756 | ElaboratedType *T = TL.getTypePtr(); |
| 2757 | |
| 2758 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2759 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2760 | if (Underlying.isNull()) |
| 2761 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2762 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2763 | QualType Result = TL.getType(); |
| 2764 | if (getDerived().AlwaysRebuild() || |
| 2765 | Underlying != T->getUnderlyingType()) { |
| 2766 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2767 | if (Result.isNull()) |
| 2768 | return QualType(); |
| 2769 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2772 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2773 | |
| 2774 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2775 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | |
| 2777 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2778 | template<typename Derived> |
| 2779 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2780 | TypeLocBuilder &TLB, |
| 2781 | TemplateTypeParmTypeLoc TL) { |
| 2782 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2785 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2786 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2787 | TypeLocBuilder &TLB, |
| 2788 | SubstTemplateTypeParmTypeLoc TL) { |
| 2789 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | template<typename Derived> |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2793 | inline QualType |
| 2794 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | TypeLocBuilder &TLB, |
| 2796 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2797 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2798 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2799 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2800 | template<typename Derived> |
| 2801 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2802 | const TemplateSpecializationType *TST, |
| 2803 | QualType ObjectType) { |
| 2804 | // FIXME: this entire method is a temporary workaround; callers |
| 2805 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2806 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2807 | // Fake up a TemplateSpecializationTypeLoc. |
| 2808 | TypeLocBuilder TLB; |
| 2809 | TemplateSpecializationTypeLoc TL |
| 2810 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2811 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2812 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2813 | |
| 2814 | TL.setTemplateNameLoc(BaseLoc); |
| 2815 | TL.setLAngleLoc(BaseLoc); |
| 2816 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2817 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2818 | const TemplateArgument &TA = TST->getArg(i); |
| 2819 | TemplateArgumentLoc TAL; |
| 2820 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2821 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2822 | } |
| 2823 | |
| 2824 | TypeLocBuilder IgnoredTLB; |
| 2825 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2829 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2830 | TypeLocBuilder &TLB, |
| 2831 | TemplateSpecializationTypeLoc TL, |
| 2832 | QualType ObjectType) { |
| 2833 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2834 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2836 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2837 | if (Template.isNull()) |
| 2838 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2839 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2840 | TemplateArgumentListInfo NewTemplateArgs; |
| 2841 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2842 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2843 | |
| 2844 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2845 | TemplateArgumentLoc Loc; |
| 2846 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2847 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2848 | NewTemplateArgs.addArgument(Loc); |
| 2849 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2850 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2851 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2852 | |
| 2853 | QualType Result = |
| 2854 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2855 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2856 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2857 | |
| 2858 | if (!Result.isNull()) { |
| 2859 | TemplateSpecializationTypeLoc NewTL |
| 2860 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2861 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2862 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2863 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2864 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2865 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2867 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2868 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2869 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2870 | |
| 2871 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2872 | QualType |
| 2873 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2874 | QualifiedNameTypeLoc TL) { |
| 2875 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2876 | NestedNameSpecifier *NNS |
| 2877 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2878 | SourceRange()); |
| 2879 | if (!NNS) |
| 2880 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2882 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2883 | if (Named.isNull()) |
| 2884 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2885 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2886 | QualType Result = TL.getType(); |
| 2887 | if (getDerived().AlwaysRebuild() || |
| 2888 | NNS != T->getQualifier() || |
| 2889 | Named != T->getNamedType()) { |
| 2890 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2891 | if (Result.isNull()) |
| 2892 | return QualType(); |
| 2893 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2894 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2895 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2896 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2897 | |
| 2898 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2900 | |
| 2901 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2902 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2903 | TypenameTypeLoc TL) { |
| 2904 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2905 | |
| 2906 | /* FIXME: preserve source information better than this */ |
| 2907 | SourceRange SR(TL.getNameLoc()); |
| 2908 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | NestedNameSpecifier *NNS |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2910 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2911 | if (!NNS) |
| 2912 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2913 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2914 | QualType Result; |
| 2915 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2916 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2917 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2918 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2919 | if (NewTemplateId.isNull()) |
| 2920 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2922 | if (!getDerived().AlwaysRebuild() && |
| 2923 | NNS == T->getQualifier() && |
| 2924 | NewTemplateId == QualType(TemplateId, 0)) |
| 2925 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2926 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2928 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2929 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2930 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2931 | if (Result.isNull()) |
| 2932 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2933 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2934 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2935 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2936 | |
| 2937 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2939 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2940 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2941 | QualType |
| 2942 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2943 | ObjCInterfaceTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2944 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2945 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2946 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2947 | |
| 2948 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2949 | QualType |
| 2950 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2951 | ObjCObjectPointerTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2952 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2953 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2956 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2957 | // Statement transformation |
| 2958 | //===----------------------------------------------------------------------===// |
| 2959 | template<typename Derived> |
| 2960 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2962 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | template<typename Derived> |
| 2966 | Sema::OwningStmtResult |
| 2967 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2968 | return getDerived().TransformCompoundStmt(S, false); |
| 2969 | } |
| 2970 | |
| 2971 | template<typename Derived> |
| 2972 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2973 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2974 | bool IsStmtExpr) { |
| 2975 | bool SubStmtChanged = false; |
| 2976 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2977 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2978 | B != BEnd; ++B) { |
| 2979 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2980 | if (Result.isInvalid()) |
| 2981 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2982 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2983 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2984 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2987 | if (!getDerived().AlwaysRebuild() && |
| 2988 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2989 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2990 | |
| 2991 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2992 | move_arg(Statements), |
| 2993 | S->getRBracLoc(), |
| 2994 | IsStmtExpr); |
| 2995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2996 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2997 | template<typename Derived> |
| 2998 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2999 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3000 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3001 | { |
| 3002 | // The case value expressions are not potentially evaluated. |
| 3003 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3005 | // Transform the left-hand case value. |
| 3006 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3007 | if (LHS.isInvalid()) |
| 3008 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3009 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3010 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3011 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3012 | if (RHS.isInvalid()) |
| 3013 | return SemaRef.StmtError(); |
| 3014 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3015 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3016 | // Build the case statement. |
| 3017 | // Case statements are always rebuilt so that they will attached to their |
| 3018 | // transformed switch statement. |
| 3019 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3020 | move(LHS), |
| 3021 | S->getEllipsisLoc(), |
| 3022 | move(RHS), |
| 3023 | S->getColonLoc()); |
| 3024 | if (Case.isInvalid()) |
| 3025 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3027 | // Transform the statement following the case |
| 3028 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3029 | if (SubStmt.isInvalid()) |
| 3030 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3031 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3032 | // Attach the body to the case statement |
| 3033 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3034 | } |
| 3035 | |
| 3036 | template<typename Derived> |
| 3037 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3038 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3039 | // Transform the statement following the default case |
| 3040 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3041 | if (SubStmt.isInvalid()) |
| 3042 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3043 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3044 | // Default statements are always rebuilt |
| 3045 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3046 | move(SubStmt)); |
| 3047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3048 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3049 | template<typename Derived> |
| 3050 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3051 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3052 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3053 | if (SubStmt.isInvalid()) |
| 3054 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3055 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3056 | // FIXME: Pass the real colon location in. |
| 3057 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3058 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3059 | move(SubStmt)); |
| 3060 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3062 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3063 | Sema::OwningStmtResult |
| 3064 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3065 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3066 | OwningExprResult Cond(SemaRef); |
| 3067 | VarDecl *ConditionVar = 0; |
| 3068 | if (S->getConditionVariable()) { |
| 3069 | ConditionVar |
| 3070 | = cast_or_null<VarDecl>( |
| 3071 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3072 | if (!ConditionVar) |
| 3073 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3074 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3075 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3076 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3077 | if (Cond.isInvalid()) |
| 3078 | return SemaRef.StmtError(); |
| 3079 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3080 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3081 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3083 | // Transform the "then" branch. |
| 3084 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3085 | if (Then.isInvalid()) |
| 3086 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3087 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3088 | // Transform the "else" branch. |
| 3089 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3090 | if (Else.isInvalid()) |
| 3091 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3092 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3093 | if (!getDerived().AlwaysRebuild() && |
| 3094 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3095 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3096 | Then.get() == S->getThen() && |
| 3097 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | return SemaRef.Owned(S->Retain()); |
| 3099 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3100 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3101 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3102 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | template<typename Derived> |
| 3106 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3107 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3108 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3109 | OwningExprResult Cond(SemaRef); |
| 3110 | VarDecl *ConditionVar = 0; |
| 3111 | if (S->getConditionVariable()) { |
| 3112 | ConditionVar |
| 3113 | = cast_or_null<VarDecl>( |
| 3114 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3115 | if (!ConditionVar) |
| 3116 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3117 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3118 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3119 | |
| 3120 | if (Cond.isInvalid()) |
| 3121 | return SemaRef.StmtError(); |
| 3122 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3123 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3124 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3125 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3126 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3127 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3128 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3129 | if (Switch.isInvalid()) |
| 3130 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3131 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3132 | // Transform the body of the switch statement. |
| 3133 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3134 | if (Body.isInvalid()) |
| 3135 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3136 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3137 | // Complete the switch statement. |
| 3138 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3139 | move(Body)); |
| 3140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3141 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3142 | template<typename Derived> |
| 3143 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3144 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3145 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3146 | OwningExprResult Cond(SemaRef); |
| 3147 | VarDecl *ConditionVar = 0; |
| 3148 | if (S->getConditionVariable()) { |
| 3149 | ConditionVar |
| 3150 | = cast_or_null<VarDecl>( |
| 3151 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3152 | if (!ConditionVar) |
| 3153 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3154 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3155 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3156 | |
| 3157 | if (Cond.isInvalid()) |
| 3158 | return SemaRef.StmtError(); |
| 3159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3160 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3161 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | // Transform the body |
| 3164 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3165 | if (Body.isInvalid()) |
| 3166 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3168 | if (!getDerived().AlwaysRebuild() && |
| 3169 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3170 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3171 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3172 | return SemaRef.Owned(S->Retain()); |
| 3173 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3174 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3175 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3177 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3178 | template<typename Derived> |
| 3179 | Sema::OwningStmtResult |
| 3180 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3181 | // Transform the condition |
| 3182 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3183 | if (Cond.isInvalid()) |
| 3184 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3185 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3186 | // Transform the body |
| 3187 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3188 | if (Body.isInvalid()) |
| 3189 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3191 | if (!getDerived().AlwaysRebuild() && |
| 3192 | Cond.get() == S->getCond() && |
| 3193 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | return SemaRef.Owned(S->Retain()); |
| 3195 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3196 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3197 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3198 | S->getRParenLoc()); |
| 3199 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3200 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3201 | template<typename Derived> |
| 3202 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | // Transform the initialization statement |
| 3205 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3206 | if (Init.isInvalid()) |
| 3207 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3208 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3209 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3210 | OwningExprResult Cond(SemaRef); |
| 3211 | VarDecl *ConditionVar = 0; |
| 3212 | if (S->getConditionVariable()) { |
| 3213 | ConditionVar |
| 3214 | = cast_or_null<VarDecl>( |
| 3215 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3216 | if (!ConditionVar) |
| 3217 | return SemaRef.StmtError(); |
| 3218 | } else { |
| 3219 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3220 | |
| 3221 | if (Cond.isInvalid()) |
| 3222 | return SemaRef.StmtError(); |
| 3223 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3224 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3225 | // Transform the increment |
| 3226 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3227 | if (Inc.isInvalid()) |
| 3228 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3230 | // Transform the body |
| 3231 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3232 | if (Body.isInvalid()) |
| 3233 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | if (!getDerived().AlwaysRebuild() && |
| 3236 | Init.get() == S->getInit() && |
| 3237 | Cond.get() == S->getCond() && |
| 3238 | Inc.get() == S->getInc() && |
| 3239 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | return SemaRef.Owned(S->Retain()); |
| 3241 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3243 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3244 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3245 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3246 | S->getRParenLoc(), move(Body)); |
| 3247 | } |
| 3248 | |
| 3249 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | Sema::OwningStmtResult |
| 3251 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3252 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3253 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3254 | S->getLabel()); |
| 3255 | } |
| 3256 | |
| 3257 | template<typename Derived> |
| 3258 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3259 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3260 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3261 | if (Target.isInvalid()) |
| 3262 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3263 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3264 | if (!getDerived().AlwaysRebuild() && |
| 3265 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3266 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3267 | |
| 3268 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3269 | move(Target)); |
| 3270 | } |
| 3271 | |
| 3272 | template<typename Derived> |
| 3273 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3274 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3275 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | template<typename Derived> |
| 3279 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3280 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3281 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3283 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | template<typename Derived> |
| 3285 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3288 | if (Result.isInvalid()) |
| 3289 | return SemaRef.StmtError(); |
| 3290 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | // to tell whether the return type of the function has changed. |
| 3293 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3294 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3296 | template<typename Derived> |
| 3297 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3298 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3299 | bool DeclChanged = false; |
| 3300 | llvm::SmallVector<Decl *, 4> Decls; |
| 3301 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3302 | D != DEnd; ++D) { |
| 3303 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3304 | if (!Transformed) |
| 3305 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3306 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3307 | if (Transformed != *D) |
| 3308 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | Decls.push_back(Transformed); |
| 3311 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3314 | return SemaRef.Owned(S->Retain()); |
| 3315 | |
| 3316 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | S->getStartLoc(), S->getEndLoc()); |
| 3318 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3320 | template<typename Derived> |
| 3321 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3322 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3323 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | template<typename Derived> |
| 3328 | Sema::OwningStmtResult |
| 3329 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3330 | // FIXME: Implement! |
| 3331 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | |
| 3336 | template<typename Derived> |
| 3337 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | // FIXME: Implement this |
| 3340 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3344 | template<typename Derived> |
| 3345 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3347 | // FIXME: Implement this |
| 3348 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3349 | return SemaRef.Owned(S->Retain()); |
| 3350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3351 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3352 | template<typename Derived> |
| 3353 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3354 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3355 | // FIXME: Implement this |
| 3356 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3358 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3360 | template<typename Derived> |
| 3361 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | // FIXME: Implement this |
| 3364 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | template<typename Derived> |
| 3369 | Sema::OwningStmtResult |
| 3370 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3371 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3372 | // FIXME: Implement this |
| 3373 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | template<typename Derived> |
| 3378 | Sema::OwningStmtResult |
| 3379 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3380 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3381 | // FIXME: Implement this |
| 3382 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | |
| 3387 | template<typename Derived> |
| 3388 | Sema::OwningStmtResult |
| 3389 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3390 | // Transform the exception declaration, if any. |
| 3391 | VarDecl *Var = 0; |
| 3392 | if (S->getExceptionDecl()) { |
| 3393 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3394 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3395 | ExceptionDecl->getDeclName()); |
| 3396 | |
| 3397 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3398 | if (T.isNull()) |
| 3399 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3401 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3402 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3403 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3404 | ExceptionDecl->getIdentifier(), |
| 3405 | ExceptionDecl->getLocation(), |
| 3406 | /*FIXME: Inaccurate*/ |
| 3407 | SourceRange(ExceptionDecl->getLocation())); |
| 3408 | if (!Var || Var->isInvalidDecl()) { |
| 3409 | if (Var) |
| 3410 | Var->Destroy(SemaRef.Context); |
| 3411 | return SemaRef.StmtError(); |
| 3412 | } |
| 3413 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3414 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3415 | // Transform the actual exception handler. |
| 3416 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3417 | if (Handler.isInvalid()) { |
| 3418 | if (Var) |
| 3419 | Var->Destroy(SemaRef.Context); |
| 3420 | return SemaRef.StmtError(); |
| 3421 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3423 | if (!getDerived().AlwaysRebuild() && |
| 3424 | !Var && |
| 3425 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3426 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3427 | |
| 3428 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3429 | Var, |
| 3430 | move(Handler)); |
| 3431 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | template<typename Derived> |
| 3434 | Sema::OwningStmtResult |
| 3435 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3436 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3439 | if (TryBlock.isInvalid()) |
| 3440 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | // Transform the handlers. |
| 3443 | bool HandlerChanged = false; |
| 3444 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3445 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3448 | if (Handler.isInvalid()) |
| 3449 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3451 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3452 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3453 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | if (!getDerived().AlwaysRebuild() && |
| 3456 | TryBlock.get() == S->getTryBlock() && |
| 3457 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3459 | |
| 3460 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3462 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3464 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3465 | // Expression transformation |
| 3466 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3467 | template<typename Derived> |
| 3468 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3469 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3470 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3471 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3472 | |
| 3473 | template<typename Derived> |
| 3474 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3475 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3476 | NestedNameSpecifier *Qualifier = 0; |
| 3477 | if (E->getQualifier()) { |
| 3478 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3479 | E->getQualifierRange()); |
| 3480 | if (!Qualifier) |
| 3481 | return SemaRef.ExprError(); |
| 3482 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3483 | |
| 3484 | ValueDecl *ND |
| 3485 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3486 | if (!ND) |
| 3487 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3489 | if (!getDerived().AlwaysRebuild() && |
| 3490 | Qualifier == E->getQualifier() && |
| 3491 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3492 | !E->hasExplicitTemplateArgumentList()) { |
| 3493 | |
| 3494 | // Mark it referenced in the new context regardless. |
| 3495 | // FIXME: this is a bit instantiation-specific. |
| 3496 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3497 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3499 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3500 | |
| 3501 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3502 | if (E->hasExplicitTemplateArgumentList()) { |
| 3503 | TemplateArgs = &TransArgs; |
| 3504 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3505 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3506 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3507 | TemplateArgumentLoc Loc; |
| 3508 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3509 | return SemaRef.ExprError(); |
| 3510 | TransArgs.addArgument(Loc); |
| 3511 | } |
| 3512 | } |
| 3513 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3514 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3515 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3518 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3520 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3524 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3525 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3526 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3528 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3529 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3530 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3532 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3536 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3538 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3542 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3544 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | return SemaRef.Owned(E->Retain()); |
| 3546 | } |
| 3547 | |
| 3548 | template<typename Derived> |
| 3549 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3550 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3551 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3552 | if (SubExpr.isInvalid()) |
| 3553 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3554 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3555 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3556 | return SemaRef.Owned(E->Retain()); |
| 3557 | |
| 3558 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3559 | E->getRParen()); |
| 3560 | } |
| 3561 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3562 | template<typename Derived> |
| 3563 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3564 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3565 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3566 | if (SubExpr.isInvalid()) |
| 3567 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3568 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3569 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3570 | return SemaRef.Owned(E->Retain()); |
| 3571 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3572 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3573 | E->getOpcode(), |
| 3574 | move(SubExpr)); |
| 3575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3576 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3577 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3578 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3579 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3580 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3581 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3582 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3583 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3584 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3585 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3587 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3588 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3589 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3590 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3591 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3592 | E->getSourceRange()); |
| 3593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3594 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3595 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3596 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3597 | // C++0x [expr.sizeof]p1: |
| 3598 | // The operand is either an expression, which is an unevaluated operand |
| 3599 | // [...] |
| 3600 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3602 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3603 | if (SubExpr.isInvalid()) |
| 3604 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3605 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3606 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3607 | return SemaRef.Owned(E->Retain()); |
| 3608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3609 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3610 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3611 | E->isSizeOf(), |
| 3612 | E->getSourceRange()); |
| 3613 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3615 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3617 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3618 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3619 | if (LHS.isInvalid()) |
| 3620 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3622 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3623 | if (RHS.isInvalid()) |
| 3624 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | |
| 3626 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3627 | if (!getDerived().AlwaysRebuild() && |
| 3628 | LHS.get() == E->getLHS() && |
| 3629 | RHS.get() == E->getRHS()) |
| 3630 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3633 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3634 | move(RHS), |
| 3635 | E->getRBracketLoc()); |
| 3636 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | |
| 3638 | template<typename Derived> |
| 3639 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3640 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3641 | // Transform the callee. |
| 3642 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3643 | if (Callee.isInvalid()) |
| 3644 | return SemaRef.ExprError(); |
| 3645 | |
| 3646 | // Transform arguments. |
| 3647 | bool ArgChanged = false; |
| 3648 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3649 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3650 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3651 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3652 | if (Arg.isInvalid()) |
| 3653 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3655 | // FIXME: Wrong source location information for the ','. |
| 3656 | FakeCommaLocs.push_back( |
| 3657 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | |
| 3659 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3660 | Args.push_back(Arg.takeAs<Expr>()); |
| 3661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3663 | if (!getDerived().AlwaysRebuild() && |
| 3664 | Callee.get() == E->getCallee() && |
| 3665 | !ArgChanged) |
| 3666 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3668 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3670 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3671 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3672 | move_arg(Args), |
| 3673 | FakeCommaLocs.data(), |
| 3674 | E->getRParenLoc()); |
| 3675 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3676 | |
| 3677 | template<typename Derived> |
| 3678 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3679 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3680 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3681 | if (Base.isInvalid()) |
| 3682 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3683 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3684 | NestedNameSpecifier *Qualifier = 0; |
| 3685 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3686 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3687 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3688 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3689 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3690 | return SemaRef.ExprError(); |
| 3691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3693 | ValueDecl *Member |
| 3694 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3695 | if (!Member) |
| 3696 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3697 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3698 | if (!getDerived().AlwaysRebuild() && |
| 3699 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3700 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3701 | Member == E->getMemberDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3702 | !E->hasExplicitTemplateArgumentList()) { |
| 3703 | |
| 3704 | // Mark it referenced in the new context regardless. |
| 3705 | // FIXME: this is a bit instantiation-specific. |
| 3706 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3707 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3708 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3709 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3710 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3711 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3712 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3713 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3714 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3715 | TemplateArgumentLoc Loc; |
| 3716 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3717 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3718 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3719 | } |
| 3720 | } |
| 3721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | // FIXME: Bogus source location for the operator |
| 3723 | SourceLocation FakeOperatorLoc |
| 3724 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3725 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3726 | // FIXME: to do this check properly, we will need to preserve the |
| 3727 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3728 | // base (and therefore couldn't do the check) and a |
| 3729 | // nested-name-qualifier (and therefore could do the lookup). |
| 3730 | NamedDecl *FirstQualifierInScope = 0; |
| 3731 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3732 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3733 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3734 | Qualifier, |
| 3735 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3736 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3737 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3738 | (E->hasExplicitTemplateArgumentList() |
| 3739 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3740 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3741 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3743 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3744 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3745 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3746 | assert(false && "Cannot transform abstract class"); |
| 3747 | return SemaRef.Owned(E->Retain()); |
| 3748 | } |
| 3749 | |
| 3750 | template<typename Derived> |
| 3751 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3752 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3753 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3754 | if (LHS.isInvalid()) |
| 3755 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3757 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3758 | if (RHS.isInvalid()) |
| 3759 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3761 | if (!getDerived().AlwaysRebuild() && |
| 3762 | LHS.get() == E->getLHS() && |
| 3763 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | return SemaRef.Owned(E->Retain()); |
| 3765 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3766 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3767 | move(LHS), move(RHS)); |
| 3768 | } |
| 3769 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3770 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | Sema::OwningExprResult |
| 3772 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3773 | CompoundAssignOperator *E) { |
| 3774 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3775 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3776 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3777 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3779 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3780 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3781 | if (Cond.isInvalid()) |
| 3782 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3784 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3785 | if (LHS.isInvalid()) |
| 3786 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3788 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3789 | if (RHS.isInvalid()) |
| 3790 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | if (!getDerived().AlwaysRebuild() && |
| 3793 | Cond.get() == E->getCond() && |
| 3794 | LHS.get() == E->getLHS() && |
| 3795 | RHS.get() == E->getRHS()) |
| 3796 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3797 | |
| 3798 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3799 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3800 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3801 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3802 | move(RHS)); |
| 3803 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3804 | |
| 3805 | template<typename Derived> |
| 3806 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3807 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3808 | // Implicit casts are eliminated during transformation, since they |
| 3809 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3810 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3811 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3812 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3813 | template<typename Derived> |
| 3814 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3815 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3816 | assert(false && "Cannot transform abstract class"); |
| 3817 | return SemaRef.Owned(E->Retain()); |
| 3818 | } |
| 3819 | |
| 3820 | template<typename Derived> |
| 3821 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3822 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3823 | TypeSourceInfo *OldT; |
| 3824 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3825 | { |
| 3826 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3827 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3828 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3829 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3830 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3831 | OldT = E->getTypeInfoAsWritten(); |
| 3832 | NewT = getDerived().TransformType(OldT); |
| 3833 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | return SemaRef.ExprError(); |
| 3835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3837 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3838 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3839 | if (SubExpr.isInvalid()) |
| 3840 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3843 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3844 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3845 | return SemaRef.Owned(E->Retain()); |
| 3846 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3847 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3848 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | E->getRParenLoc(), |
| 3850 | move(SubExpr)); |
| 3851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3853 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3854 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3855 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | QualType T; |
| 3857 | { |
| 3858 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3859 | SourceLocation FakeTypeLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3860 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3861 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3862 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3863 | T = getDerived().TransformType(E->getType()); |
| 3864 | if (T.isNull()) |
| 3865 | return SemaRef.ExprError(); |
| 3866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3869 | if (Init.isInvalid()) |
| 3870 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3872 | if (!getDerived().AlwaysRebuild() && |
| 3873 | T == E->getType() && |
| 3874 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3875 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3876 | |
| 3877 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3878 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3879 | move(Init)); |
| 3880 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3882 | template<typename Derived> |
| 3883 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3884 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3885 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3886 | if (Base.isInvalid()) |
| 3887 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3889 | if (!getDerived().AlwaysRebuild() && |
| 3890 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3891 | return SemaRef.Owned(E->Retain()); |
| 3892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3893 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3894 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3895 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3896 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3897 | E->getAccessorLoc(), |
| 3898 | E->getAccessor()); |
| 3899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3900 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3901 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3902 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3903 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3904 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3905 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3907 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3908 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3909 | if (Init.isInvalid()) |
| 3910 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3913 | Inits.push_back(Init.takeAs<Expr>()); |
| 3914 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | return SemaRef.Owned(E->Retain()); |
| 3918 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3919 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3920 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3923 | template<typename Derived> |
| 3924 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3925 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3926 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3927 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3928 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3930 | if (Init.isInvalid()) |
| 3931 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3932 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3933 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3935 | bool ExprChanged = false; |
| 3936 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3937 | DEnd = E->designators_end(); |
| 3938 | D != DEnd; ++D) { |
| 3939 | if (D->isFieldDesignator()) { |
| 3940 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3941 | D->getDotLoc(), |
| 3942 | D->getFieldLoc())); |
| 3943 | continue; |
| 3944 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3946 | if (D->isArrayDesignator()) { |
| 3947 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3948 | if (Index.isInvalid()) |
| 3949 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
| 3951 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3953 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3954 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3955 | ArrayExprs.push_back(Index.release()); |
| 3956 | continue; |
| 3957 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3958 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3961 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3962 | if (Start.isInvalid()) |
| 3963 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3964 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3965 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3966 | if (End.isInvalid()) |
| 3967 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | |
| 3969 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3970 | End.get(), |
| 3971 | D->getLBracketLoc(), |
| 3972 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3973 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3974 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3975 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3977 | ArrayExprs.push_back(Start.release()); |
| 3978 | ArrayExprs.push_back(End.release()); |
| 3979 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3981 | if (!getDerived().AlwaysRebuild() && |
| 3982 | Init.get() == E->getInit() && |
| 3983 | !ExprChanged) |
| 3984 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3985 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3986 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3987 | E->getEqualOrColonLoc(), |
| 3988 | E->usesGNUSyntax(), move(Init)); |
| 3989 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3990 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3991 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3994 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3995 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3996 | |
| 3997 | // FIXME: Will we ever have proper type location here? Will we actually |
| 3998 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | QualType T = getDerived().TransformType(E->getType()); |
| 4000 | if (T.isNull()) |
| 4001 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | if (!getDerived().AlwaysRebuild() && |
| 4004 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | return SemaRef.Owned(E->Retain()); |
| 4006 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4007 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4010 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4011 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4012 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4013 | // FIXME: Do we want the type as written? |
| 4014 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4015 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4016 | { |
| 4017 | // FIXME: Source location isn't quite accurate. |
| 4018 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4019 | T = getDerived().TransformType(E->getType()); |
| 4020 | if (T.isNull()) |
| 4021 | return SemaRef.ExprError(); |
| 4022 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4025 | if (SubExpr.isInvalid()) |
| 4026 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | if (!getDerived().AlwaysRebuild() && |
| 4029 | T == E->getType() && |
| 4030 | SubExpr.get() == E->getSubExpr()) |
| 4031 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4034 | T, E->getRParenLoc()); |
| 4035 | } |
| 4036 | |
| 4037 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4038 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4039 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4040 | bool ArgumentChanged = false; |
| 4041 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4042 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4043 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4044 | if (Init.isInvalid()) |
| 4045 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4047 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4048 | Inits.push_back(Init.takeAs<Expr>()); |
| 4049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4052 | move_arg(Inits), |
| 4053 | E->getRParenLoc()); |
| 4054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4055 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4056 | /// \brief Transform an address-of-label expression. |
| 4057 | /// |
| 4058 | /// By default, the transformation of an address-of-label expression always |
| 4059 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4060 | /// the corresponding label statement by semantic analysis. |
| 4061 | template<typename Derived> |
| 4062 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4063 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4065 | E->getLabel()); |
| 4066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4067 | |
| 4068 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4069 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4070 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4071 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4072 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4073 | if (SubStmt.isInvalid()) |
| 4074 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4075 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4076 | if (!getDerived().AlwaysRebuild() && |
| 4077 | SubStmt.get() == E->getSubStmt()) |
| 4078 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4079 | |
| 4080 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4081 | move(SubStmt), |
| 4082 | E->getRParenLoc()); |
| 4083 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4084 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4085 | template<typename Derived> |
| 4086 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4087 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | QualType T1, T2; |
| 4089 | { |
| 4090 | // FIXME: Source location isn't quite accurate. |
| 4091 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4094 | if (T1.isNull()) |
| 4095 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4098 | if (T2.isNull()) |
| 4099 | return SemaRef.ExprError(); |
| 4100 | } |
| 4101 | |
| 4102 | if (!getDerived().AlwaysRebuild() && |
| 4103 | T1 == E->getArgType1() && |
| 4104 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | return SemaRef.Owned(E->Retain()); |
| 4106 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4107 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4108 | T1, T2, E->getRParenLoc()); |
| 4109 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4111 | template<typename Derived> |
| 4112 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4113 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4115 | if (Cond.isInvalid()) |
| 4116 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4119 | if (LHS.isInvalid()) |
| 4120 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4121 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4122 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4123 | if (RHS.isInvalid()) |
| 4124 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4125 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4126 | if (!getDerived().AlwaysRebuild() && |
| 4127 | Cond.get() == E->getCond() && |
| 4128 | LHS.get() == E->getLHS() && |
| 4129 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4130 | return SemaRef.Owned(E->Retain()); |
| 4131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4133 | move(Cond), move(LHS), move(RHS), |
| 4134 | E->getRParenLoc()); |
| 4135 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4137 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4139 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | template<typename Derived> |
| 4144 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4145 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4146 | switch (E->getOperator()) { |
| 4147 | case OO_New: |
| 4148 | case OO_Delete: |
| 4149 | case OO_Array_New: |
| 4150 | case OO_Array_Delete: |
| 4151 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4152 | return SemaRef.ExprError(); |
| 4153 | |
| 4154 | case OO_Call: { |
| 4155 | // This is a call to an object's operator(). |
| 4156 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4157 | |
| 4158 | // Transform the object itself. |
| 4159 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4160 | if (Object.isInvalid()) |
| 4161 | return SemaRef.ExprError(); |
| 4162 | |
| 4163 | // FIXME: Poor location information |
| 4164 | SourceLocation FakeLParenLoc |
| 4165 | = SemaRef.PP.getLocForEndOfToken( |
| 4166 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4167 | |
| 4168 | // Transform the call arguments. |
| 4169 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4170 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4171 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4172 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4173 | break; |
| 4174 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4175 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4176 | if (Arg.isInvalid()) |
| 4177 | return SemaRef.ExprError(); |
| 4178 | |
| 4179 | // FIXME: Poor source location information. |
| 4180 | SourceLocation FakeCommaLoc |
| 4181 | = SemaRef.PP.getLocForEndOfToken( |
| 4182 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4183 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4184 | Args.push_back(Arg.release()); |
| 4185 | } |
| 4186 | |
| 4187 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4188 | move_arg(Args), |
| 4189 | FakeCommaLocs.data(), |
| 4190 | E->getLocEnd()); |
| 4191 | } |
| 4192 | |
| 4193 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4194 | case OO_##Name: |
| 4195 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4196 | #include "clang/Basic/OperatorKinds.def" |
| 4197 | case OO_Subscript: |
| 4198 | // Handled below. |
| 4199 | break; |
| 4200 | |
| 4201 | case OO_Conditional: |
| 4202 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4203 | return SemaRef.ExprError(); |
| 4204 | |
| 4205 | case OO_None: |
| 4206 | case NUM_OVERLOADED_OPERATORS: |
| 4207 | llvm_unreachable("not an overloaded operator?"); |
| 4208 | return SemaRef.ExprError(); |
| 4209 | } |
| 4210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4212 | if (Callee.isInvalid()) |
| 4213 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4215 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4216 | if (First.isInvalid()) |
| 4217 | return SemaRef.ExprError(); |
| 4218 | |
| 4219 | OwningExprResult Second(SemaRef); |
| 4220 | if (E->getNumArgs() == 2) { |
| 4221 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4222 | if (Second.isInvalid()) |
| 4223 | return SemaRef.ExprError(); |
| 4224 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | if (!getDerived().AlwaysRebuild() && |
| 4227 | Callee.get() == E->getCallee() && |
| 4228 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4230 | return SemaRef.Owned(E->Retain()); |
| 4231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4233 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4234 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | move(First), |
| 4236 | move(Second)); |
| 4237 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | template<typename Derived> |
| 4240 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4241 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4242 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4243 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4245 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4247 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4248 | TypeSourceInfo *OldT; |
| 4249 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4250 | { |
| 4251 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4252 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4253 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4254 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4256 | OldT = E->getTypeInfoAsWritten(); |
| 4257 | NewT = getDerived().TransformType(OldT); |
| 4258 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4259 | return SemaRef.ExprError(); |
| 4260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4262 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4263 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | if (SubExpr.isInvalid()) |
| 4265 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4266 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4267 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4268 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4269 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | return SemaRef.Owned(E->Retain()); |
| 4271 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4272 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4273 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4274 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4275 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4276 | SourceLocation FakeRParenLoc |
| 4277 | = SemaRef.PP.getLocForEndOfToken( |
| 4278 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4279 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4280 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4282 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4283 | FakeRAngleLoc, |
| 4284 | FakeRAngleLoc, |
| 4285 | move(SubExpr), |
| 4286 | FakeRParenLoc); |
| 4287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | template<typename Derived> |
| 4290 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4291 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4292 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4293 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4294 | |
| 4295 | template<typename Derived> |
| 4296 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4297 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4298 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4299 | } |
| 4300 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | template<typename Derived> |
| 4302 | Sema::OwningExprResult |
| 4303 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4304 | CXXReinterpretCastExpr *E) { |
| 4305 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4308 | template<typename Derived> |
| 4309 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4310 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4311 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4312 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4313 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4314 | template<typename Derived> |
| 4315 | Sema::OwningExprResult |
| 4316 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4317 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4318 | TypeSourceInfo *OldT; |
| 4319 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4320 | { |
| 4321 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4322 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4323 | OldT = E->getTypeInfoAsWritten(); |
| 4324 | NewT = getDerived().TransformType(OldT); |
| 4325 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | return SemaRef.ExprError(); |
| 4327 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4328 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4329 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4330 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | if (SubExpr.isInvalid()) |
| 4332 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4333 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4334 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4335 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4337 | return SemaRef.Owned(E->Retain()); |
| 4338 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | // FIXME: The end of the type's source range is wrong |
| 4340 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4341 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4342 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4344 | move(SubExpr), |
| 4345 | E->getRParenLoc()); |
| 4346 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | template<typename Derived> |
| 4349 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4350 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | if (E->isTypeOperand()) { |
| 4352 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4354 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4355 | if (T.isNull()) |
| 4356 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | if (!getDerived().AlwaysRebuild() && |
| 4359 | T == E->getTypeOperand()) |
| 4360 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4361 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4363 | /*FIXME:*/E->getLocStart(), |
| 4364 | T, |
| 4365 | E->getLocEnd()); |
| 4366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4367 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4368 | // We don't know whether the expression is potentially evaluated until |
| 4369 | // after we perform semantic analysis, so the expression is potentially |
| 4370 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4371 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4373 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4375 | if (SubExpr.isInvalid()) |
| 4376 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4378 | if (!getDerived().AlwaysRebuild() && |
| 4379 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4380 | return SemaRef.Owned(E->Retain()); |
| 4381 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4383 | /*FIXME:*/E->getLocStart(), |
| 4384 | move(SubExpr), |
| 4385 | E->getLocEnd()); |
| 4386 | } |
| 4387 | |
| 4388 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4390 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | template<typename Derived> |
| 4395 | Sema::OwningExprResult |
| 4396 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4397 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4398 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4399 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4400 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4401 | template<typename Derived> |
| 4402 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4403 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4404 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | QualType T = getDerived().TransformType(E->getType()); |
| 4407 | if (T.isNull()) |
| 4408 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | if (!getDerived().AlwaysRebuild() && |
| 4411 | T == E->getType()) |
| 4412 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4414 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | template<typename Derived> |
| 4418 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4419 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4420 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4421 | if (SubExpr.isInvalid()) |
| 4422 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4423 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4424 | if (!getDerived().AlwaysRebuild() && |
| 4425 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | |
| 4428 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | template<typename Derived> |
| 4432 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4433 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4436 | if (!Param) |
| 4437 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4439 | if (getDerived().AlwaysRebuild() && |
| 4440 | Param == E->getParam()) |
| 4441 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4442 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4443 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | template<typename Derived> |
| 4447 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4448 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4449 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4450 | |
| 4451 | QualType T = getDerived().TransformType(E->getType()); |
| 4452 | if (T.isNull()) |
| 4453 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4454 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4455 | if (!getDerived().AlwaysRebuild() && |
| 4456 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4457 | return SemaRef.Owned(E->Retain()); |
| 4458 | |
| 4459 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4460 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4461 | T, |
| 4462 | E->getRParenLoc()); |
| 4463 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4464 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4465 | template<typename Derived> |
| 4466 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4467 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | // Transform the type that we're allocating |
| 4469 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4470 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4471 | if (AllocType.isNull()) |
| 4472 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4474 | // Transform the size of the array we're allocating (if any). |
| 4475 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4476 | if (ArraySize.isInvalid()) |
| 4477 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | // Transform the placement arguments (if any). |
| 4480 | bool ArgumentChanged = false; |
| 4481 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4482 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4483 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4484 | if (Arg.isInvalid()) |
| 4485 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4487 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4488 | PlacementArgs.push_back(Arg.take()); |
| 4489 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4491 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4493 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4494 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4495 | if (Arg.isInvalid()) |
| 4496 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4497 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4498 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4499 | ConstructorArgs.push_back(Arg.take()); |
| 4500 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4501 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | if (!getDerived().AlwaysRebuild() && |
| 4503 | AllocType == E->getAllocatedType() && |
| 4504 | ArraySize.get() == E->getArraySize() && |
| 4505 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | return SemaRef.Owned(E->Retain()); |
| 4507 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4508 | if (!ArraySize.get()) { |
| 4509 | // If no array size was specified, but the new expression was |
| 4510 | // instantiated with an array type (e.g., "new T" where T is |
| 4511 | // instantiated with "int[4]"), extract the outer bound from the |
| 4512 | // array type as our array size. We do this with constant and |
| 4513 | // dependently-sized array types. |
| 4514 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4515 | if (!ArrayT) { |
| 4516 | // Do nothing |
| 4517 | } else if (const ConstantArrayType *ConsArrayT |
| 4518 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4519 | ArraySize |
| 4520 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4521 | ConsArrayT->getSize(), |
| 4522 | SemaRef.Context.getSizeType(), |
| 4523 | /*FIXME:*/E->getLocStart())); |
| 4524 | AllocType = ConsArrayT->getElementType(); |
| 4525 | } else if (const DependentSizedArrayType *DepArrayT |
| 4526 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4527 | if (DepArrayT->getSizeExpr()) { |
| 4528 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4529 | AllocType = DepArrayT->getElementType(); |
| 4530 | } |
| 4531 | } |
| 4532 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4533 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4534 | E->isGlobalNew(), |
| 4535 | /*FIXME:*/E->getLocStart(), |
| 4536 | move_arg(PlacementArgs), |
| 4537 | /*FIXME:*/E->getLocStart(), |
| 4538 | E->isParenTypeId(), |
| 4539 | AllocType, |
| 4540 | /*FIXME:*/E->getLocStart(), |
| 4541 | /*FIXME:*/SourceRange(), |
| 4542 | move(ArraySize), |
| 4543 | /*FIXME:*/E->getLocStart(), |
| 4544 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4545 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4548 | template<typename Derived> |
| 4549 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4550 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4551 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4552 | if (Operand.isInvalid()) |
| 4553 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4555 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | Operand.get() == E->getArgument()) |
| 4557 | return SemaRef.Owned(E->Retain()); |
| 4558 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4560 | E->isGlobalDelete(), |
| 4561 | E->isArrayForm(), |
| 4562 | move(Operand)); |
| 4563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | template<typename Derived> |
| 4566 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4567 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4568 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4569 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4570 | if (Base.isInvalid()) |
| 4571 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4572 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4573 | NestedNameSpecifier *Qualifier |
| 4574 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4575 | E->getQualifierRange()); |
| 4576 | if (E->getQualifier() && !Qualifier) |
| 4577 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4579 | QualType DestroyedType; |
| 4580 | { |
| 4581 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4582 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4583 | if (DestroyedType.isNull()) |
| 4584 | return SemaRef.ExprError(); |
| 4585 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4586 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4587 | if (!getDerived().AlwaysRebuild() && |
| 4588 | Base.get() == E->getBase() && |
| 4589 | Qualifier == E->getQualifier() && |
| 4590 | DestroyedType == E->getDestroyedType()) |
| 4591 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4592 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4593 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4594 | E->getOperatorLoc(), |
| 4595 | E->isArrow(), |
| 4596 | E->getDestroyedTypeLoc(), |
| 4597 | DestroyedType, |
| 4598 | Qualifier, |
| 4599 | E->getQualifierRange()); |
| 4600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4601 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4602 | template<typename Derived> |
| 4603 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4604 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4605 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4606 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4607 | |
| 4608 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4609 | Sema::LookupOrdinaryName); |
| 4610 | |
| 4611 | // Transform all the decls. |
| 4612 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4613 | E = Old->decls_end(); I != E; ++I) { |
| 4614 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4615 | if (!InstD) { |
| 4616 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4617 | // This can happen because of dependent hiding. |
| 4618 | if (isa<UsingShadowDecl>(*I)) |
| 4619 | continue; |
| 4620 | else |
| 4621 | return SemaRef.ExprError(); |
| 4622 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4623 | |
| 4624 | // Expand using declarations. |
| 4625 | if (isa<UsingDecl>(InstD)) { |
| 4626 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4627 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4628 | E = UD->shadow_end(); I != E; ++I) |
| 4629 | R.addDecl(*I); |
| 4630 | continue; |
| 4631 | } |
| 4632 | |
| 4633 | R.addDecl(InstD); |
| 4634 | } |
| 4635 | |
| 4636 | // Resolve a kind, but don't do any further analysis. If it's |
| 4637 | // ambiguous, the callee needs to deal with it. |
| 4638 | R.resolveKind(); |
| 4639 | |
| 4640 | // Rebuild the nested-name qualifier, if present. |
| 4641 | CXXScopeSpec SS; |
| 4642 | NestedNameSpecifier *Qualifier = 0; |
| 4643 | if (Old->getQualifier()) { |
| 4644 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4645 | Old->getQualifierRange()); |
| 4646 | if (!Qualifier) |
| 4647 | return SemaRef.ExprError(); |
| 4648 | |
| 4649 | SS.setScopeRep(Qualifier); |
| 4650 | SS.setRange(Old->getQualifierRange()); |
| 4651 | } |
| 4652 | |
| 4653 | // If we have no template arguments, it's a normal declaration name. |
| 4654 | if (!Old->hasExplicitTemplateArgs()) |
| 4655 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4656 | |
| 4657 | // If we have template arguments, rebuild them, then rebuild the |
| 4658 | // templateid expression. |
| 4659 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4660 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4661 | TemplateArgumentLoc Loc; |
| 4662 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4663 | return SemaRef.ExprError(); |
| 4664 | TransArgs.addArgument(Loc); |
| 4665 | } |
| 4666 | |
| 4667 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4668 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4671 | template<typename Derived> |
| 4672 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4673 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4674 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4677 | if (T.isNull()) |
| 4678 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | if (!getDerived().AlwaysRebuild() && |
| 4681 | T == E->getQueriedType()) |
| 4682 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4684 | // FIXME: Bad location information |
| 4685 | SourceLocation FakeLParenLoc |
| 4686 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | |
| 4688 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4689 | E->getLocStart(), |
| 4690 | /*FIXME:*/FakeLParenLoc, |
| 4691 | T, |
| 4692 | E->getLocEnd()); |
| 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> |
| 4696 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4697 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4698 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4699 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4700 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4701 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4702 | if (!NNS) |
| 4703 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | |
| 4705 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4706 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4707 | if (!Name) |
| 4708 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4709 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4710 | if (!E->hasExplicitTemplateArgs()) { |
| 4711 | if (!getDerived().AlwaysRebuild() && |
| 4712 | NNS == E->getQualifier() && |
| 4713 | Name == E->getDeclName()) |
| 4714 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4715 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4716 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4717 | E->getQualifierRange(), |
| 4718 | Name, E->getLocation(), |
| 4719 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4720 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4721 | |
| 4722 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4724 | TemplateArgumentLoc Loc; |
| 4725 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4726 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4727 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4730 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4731 | E->getQualifierRange(), |
| 4732 | Name, E->getLocation(), |
| 4733 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4734 | } |
| 4735 | |
| 4736 | template<typename Derived> |
| 4737 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4738 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4739 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4740 | |
| 4741 | QualType T = getDerived().TransformType(E->getType()); |
| 4742 | if (T.isNull()) |
| 4743 | return SemaRef.ExprError(); |
| 4744 | |
| 4745 | CXXConstructorDecl *Constructor |
| 4746 | = cast_or_null<CXXConstructorDecl>( |
| 4747 | getDerived().TransformDecl(E->getConstructor())); |
| 4748 | if (!Constructor) |
| 4749 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4751 | bool ArgumentChanged = false; |
| 4752 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4754 | ArgEnd = E->arg_end(); |
| 4755 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4756 | if (getDerived().DropCallArgument(*Arg)) { |
| 4757 | ArgumentChanged = true; |
| 4758 | break; |
| 4759 | } |
| 4760 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4761 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4762 | if (TransArg.isInvalid()) |
| 4763 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4765 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4766 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4767 | } |
| 4768 | |
| 4769 | if (!getDerived().AlwaysRebuild() && |
| 4770 | T == E->getType() && |
| 4771 | Constructor == E->getConstructor() && |
| 4772 | !ArgumentChanged) |
| 4773 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4775 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4776 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4777 | move_arg(Args)); |
| 4778 | } |
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 | /// \brief Transform a C++ temporary-binding expression. |
| 4781 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4782 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4783 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4784 | template<typename Derived> |
| 4785 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4786 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4787 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
| 4790 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | /// be destroyed after the expression is evaluated. |
| 4792 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4793 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4794 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4795 | template<typename Derived> |
| 4796 | Sema::OwningExprResult |
| 4797 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4798 | CXXExprWithTemporaries *E) { |
| 4799 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4802 | template<typename Derived> |
| 4803 | Sema::OwningExprResult |
| 4804 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4805 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4806 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4807 | QualType T = getDerived().TransformType(E->getType()); |
| 4808 | if (T.isNull()) |
| 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 | CXXConstructorDecl *Constructor |
| 4812 | = cast_or_null<CXXConstructorDecl>( |
| 4813 | getDerived().TransformDecl(E->getConstructor())); |
| 4814 | if (!Constructor) |
| 4815 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4817 | bool ArgumentChanged = false; |
| 4818 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4819 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4821 | ArgEnd = E->arg_end(); |
| 4822 | Arg != ArgEnd; ++Arg) { |
| 4823 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4824 | if (TransArg.isInvalid()) |
| 4825 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4826 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4827 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4828 | Args.push_back((Expr *)TransArg.release()); |
| 4829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4830 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4831 | if (!getDerived().AlwaysRebuild() && |
| 4832 | T == E->getType() && |
| 4833 | Constructor == E->getConstructor() && |
| 4834 | !ArgumentChanged) |
| 4835 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4836 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4837 | // FIXME: Bogus location information |
| 4838 | SourceLocation CommaLoc; |
| 4839 | if (Args.size() > 1) { |
| 4840 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4841 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4842 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4843 | } |
| 4844 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4845 | T, |
| 4846 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4847 | move_arg(Args), |
| 4848 | &CommaLoc, |
| 4849 | E->getLocEnd()); |
| 4850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4851 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4852 | template<typename Derived> |
| 4853 | Sema::OwningExprResult |
| 4854 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4855 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4856 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4857 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4858 | if (T.isNull()) |
| 4859 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4861 | bool ArgumentChanged = false; |
| 4862 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4863 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4864 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4865 | ArgEnd = E->arg_end(); |
| 4866 | Arg != ArgEnd; ++Arg) { |
| 4867 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4868 | if (TransArg.isInvalid()) |
| 4869 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4870 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4871 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4872 | FakeCommaLocs.push_back( |
| 4873 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4874 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4875 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4876 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4877 | if (!getDerived().AlwaysRebuild() && |
| 4878 | T == E->getTypeAsWritten() && |
| 4879 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4880 | return SemaRef.Owned(E->Retain()); |
| 4881 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4882 | // FIXME: we're faking the locations of the commas |
| 4883 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4884 | T, |
| 4885 | E->getLParenLoc(), |
| 4886 | move_arg(Args), |
| 4887 | FakeCommaLocs.data(), |
| 4888 | E->getRParenLoc()); |
| 4889 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4891 | template<typename Derived> |
| 4892 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4893 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4894 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4895 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4896 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4897 | Expr *OldBase; |
| 4898 | QualType BaseType; |
| 4899 | QualType ObjectType; |
| 4900 | if (!E->isImplicitAccess()) { |
| 4901 | OldBase = E->getBase(); |
| 4902 | Base = getDerived().TransformExpr(OldBase); |
| 4903 | if (Base.isInvalid()) |
| 4904 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4905 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4906 | // Start the member reference and compute the object's type. |
| 4907 | Sema::TypeTy *ObjectTy = 0; |
| 4908 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4909 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4910 | E->isArrow()? tok::arrow : tok::period, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4911 | ObjectTy); |
| 4912 | if (Base.isInvalid()) |
| 4913 | return SemaRef.ExprError(); |
| 4914 | |
| 4915 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 4916 | BaseType = ((Expr*) Base.get())->getType(); |
| 4917 | } else { |
| 4918 | OldBase = 0; |
| 4919 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 4920 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 4921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4922 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4923 | // Transform the first part of the nested-name-specifier that qualifies |
| 4924 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4925 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4926 | = getDerived().TransformFirstQualifierInScope( |
| 4927 | E->getFirstQualifierFoundInScope(), |
| 4928 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4929 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4930 | NestedNameSpecifier *Qualifier = 0; |
| 4931 | if (E->getQualifier()) { |
| 4932 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4933 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4934 | ObjectType, |
| 4935 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4936 | if (!Qualifier) |
| 4937 | return SemaRef.ExprError(); |
| 4938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4939 | |
| 4940 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4941 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4942 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4943 | if (!Name) |
| 4944 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4945 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4946 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4947 | // This is a reference to a member without an explicitly-specified |
| 4948 | // template argument list. Optimize for this common case. |
| 4949 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4950 | Base.get() == OldBase && |
| 4951 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4952 | Qualifier == E->getQualifier() && |
| 4953 | Name == E->getMember() && |
| 4954 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4955 | return SemaRef.Owned(E->Retain()); |
| 4956 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4957 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4958 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4959 | E->isArrow(), |
| 4960 | E->getOperatorLoc(), |
| 4961 | Qualifier, |
| 4962 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4963 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4964 | Name, |
| 4965 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4966 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4967 | } |
| 4968 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4969 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4970 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4971 | TemplateArgumentLoc Loc; |
| 4972 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4973 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4974 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4975 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4976 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4977 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4978 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4979 | E->isArrow(), |
| 4980 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4981 | Qualifier, |
| 4982 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4983 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4984 | Name, |
| 4985 | E->getMemberLoc(), |
| 4986 | &TransArgs); |
| 4987 | } |
| 4988 | |
| 4989 | template<typename Derived> |
| 4990 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4991 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4992 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4993 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4994 | QualType BaseType; |
| 4995 | if (!Old->isImplicitAccess()) { |
| 4996 | Base = getDerived().TransformExpr(Old->getBase()); |
| 4997 | if (Base.isInvalid()) |
| 4998 | return SemaRef.ExprError(); |
| 4999 | BaseType = ((Expr*) Base.get())->getType(); |
| 5000 | } else { |
| 5001 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5002 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5003 | |
| 5004 | NestedNameSpecifier *Qualifier = 0; |
| 5005 | if (Old->getQualifier()) { |
| 5006 | Qualifier |
| 5007 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 5008 | Old->getQualifierRange()); |
| 5009 | if (Qualifier == 0) |
| 5010 | return SemaRef.ExprError(); |
| 5011 | } |
| 5012 | |
| 5013 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5014 | Sema::LookupOrdinaryName); |
| 5015 | |
| 5016 | // Transform all the decls. |
| 5017 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5018 | E = Old->decls_end(); I != E; ++I) { |
| 5019 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5020 | if (!InstD) { |
| 5021 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5022 | // This can happen because of dependent hiding. |
| 5023 | if (isa<UsingShadowDecl>(*I)) |
| 5024 | continue; |
| 5025 | else |
| 5026 | return SemaRef.ExprError(); |
| 5027 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5028 | |
| 5029 | // Expand using declarations. |
| 5030 | if (isa<UsingDecl>(InstD)) { |
| 5031 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5032 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5033 | E = UD->shadow_end(); I != E; ++I) |
| 5034 | R.addDecl(*I); |
| 5035 | continue; |
| 5036 | } |
| 5037 | |
| 5038 | R.addDecl(InstD); |
| 5039 | } |
| 5040 | |
| 5041 | R.resolveKind(); |
| 5042 | |
| 5043 | TemplateArgumentListInfo TransArgs; |
| 5044 | if (Old->hasExplicitTemplateArgs()) { |
| 5045 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5046 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5047 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5048 | TemplateArgumentLoc Loc; |
| 5049 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5050 | Loc)) |
| 5051 | return SemaRef.ExprError(); |
| 5052 | TransArgs.addArgument(Loc); |
| 5053 | } |
| 5054 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5055 | |
| 5056 | // FIXME: to do this check properly, we will need to preserve the |
| 5057 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5058 | // base (and therefore couldn't do the check) and a |
| 5059 | // nested-name-qualifier (and therefore could do the lookup). |
| 5060 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5061 | |
| 5062 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5063 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5064 | Old->getOperatorLoc(), |
| 5065 | Old->isArrow(), |
| 5066 | Qualifier, |
| 5067 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5068 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5069 | R, |
| 5070 | (Old->hasExplicitTemplateArgs() |
| 5071 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | template<typename Derived> |
| 5075 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5076 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | template<typename Derived> |
| 5081 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5082 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5083 | // FIXME: poor source location |
| 5084 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5085 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5086 | if (EncodedType.isNull()) |
| 5087 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5089 | if (!getDerived().AlwaysRebuild() && |
| 5090 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5092 | |
| 5093 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5094 | EncodedType, |
| 5095 | E->getRParenLoc()); |
| 5096 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5098 | template<typename Derived> |
| 5099 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5100 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5101 | // FIXME: Implement this! |
| 5102 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5103 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5104 | } |
| 5105 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5106 | template<typename Derived> |
| 5107 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5108 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5110 | } |
| 5111 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5112 | template<typename Derived> |
| 5113 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5114 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5115 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5116 | = cast_or_null<ObjCProtocolDecl>( |
| 5117 | getDerived().TransformDecl(E->getProtocol())); |
| 5118 | if (!Protocol) |
| 5119 | return SemaRef.ExprError(); |
| 5120 | |
| 5121 | if (!getDerived().AlwaysRebuild() && |
| 5122 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5123 | return SemaRef.Owned(E->Retain()); |
| 5124 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5125 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5126 | E->getAtLoc(), |
| 5127 | /*FIXME:*/E->getAtLoc(), |
| 5128 | /*FIXME:*/E->getAtLoc(), |
| 5129 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5130 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5131 | } |
| 5132 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5136 | // FIXME: Implement this! |
| 5137 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5138 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5139 | } |
| 5140 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | template<typename Derived> |
| 5142 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5143 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5144 | // FIXME: Implement this! |
| 5145 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5146 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5147 | } |
| 5148 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | template<typename Derived> |
| 5150 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5151 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5152 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5153 | // FIXME: Implement this! |
| 5154 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5155 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5156 | } |
| 5157 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | template<typename Derived> |
| 5159 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5160 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | // FIXME: Implement this! |
| 5162 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5163 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5166 | template<typename Derived> |
| 5167 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5168 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5169 | // FIXME: Implement this! |
| 5170 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | } |
| 5173 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5174 | template<typename Derived> |
| 5175 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5176 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | bool ArgumentChanged = false; |
| 5178 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5179 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5180 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5181 | if (SubExpr.isInvalid()) |
| 5182 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5183 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5185 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5188 | if (!getDerived().AlwaysRebuild() && |
| 5189 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | return SemaRef.Owned(E->Retain()); |
| 5191 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5193 | move_arg(SubExprs), |
| 5194 | E->getRParenLoc()); |
| 5195 | } |
| 5196 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | template<typename Derived> |
| 5198 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5199 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5200 | // FIXME: Implement this! |
| 5201 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5202 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5205 | template<typename Derived> |
| 5206 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5207 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5208 | // FIXME: Implement this! |
| 5209 | assert(false && "Cannot transform block-related expressions yet"); |
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 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5213 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5214 | // Type reconstruction |
| 5215 | //===----------------------------------------------------------------------===// |
| 5216 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5218 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5219 | SourceLocation Star) { |
| 5220 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5221 | getDerived().getBaseEntity()); |
| 5222 | } |
| 5223 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5224 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5225 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5226 | SourceLocation Star) { |
| 5227 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5228 | getDerived().getBaseEntity()); |
| 5229 | } |
| 5230 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | template<typename Derived> |
| 5232 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5233 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5234 | bool WrittenAsLValue, |
| 5235 | SourceLocation Sigil) { |
| 5236 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5237 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
| 5240 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5241 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5242 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5243 | QualType ClassType, |
| 5244 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5245 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5246 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5250 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5251 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5252 | SourceLocation Sigil) { |
| 5253 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5254 | getDerived().getBaseEntity()); |
| 5255 | } |
| 5256 | |
| 5257 | template<typename Derived> |
| 5258 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5259 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5260 | ArrayType::ArraySizeModifier SizeMod, |
| 5261 | const llvm::APInt *Size, |
| 5262 | Expr *SizeExpr, |
| 5263 | unsigned IndexTypeQuals, |
| 5264 | SourceRange BracketsRange) { |
| 5265 | if (SizeExpr || !Size) |
| 5266 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5267 | IndexTypeQuals, BracketsRange, |
| 5268 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5269 | |
| 5270 | QualType Types[] = { |
| 5271 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5272 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5273 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5274 | }; |
| 5275 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5276 | QualType SizeType; |
| 5277 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5278 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5279 | SizeType = Types[I]; |
| 5280 | break; |
| 5281 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5282 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5283 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5285 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5286 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5288 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5289 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5290 | QualType |
| 5291 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5292 | ArrayType::ArraySizeModifier SizeMod, |
| 5293 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5294 | unsigned IndexTypeQuals, |
| 5295 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5296 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5297 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5301 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5303 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5304 | unsigned IndexTypeQuals, |
| 5305 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5306 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5307 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5309 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5310 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | QualType |
| 5312 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5313 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5314 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5315 | unsigned IndexTypeQuals, |
| 5316 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5318 | SizeExpr.takeAs<Expr>(), |
| 5319 | IndexTypeQuals, BracketsRange); |
| 5320 | } |
| 5321 | |
| 5322 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | QualType |
| 5324 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5325 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5326 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5327 | unsigned IndexTypeQuals, |
| 5328 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5329 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5330 | SizeExpr.takeAs<Expr>(), |
| 5331 | IndexTypeQuals, BracketsRange); |
| 5332 | } |
| 5333 | |
| 5334 | template<typename Derived> |
| 5335 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5336 | unsigned NumElements) { |
| 5337 | // FIXME: semantic checking! |
| 5338 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5339 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5341 | template<typename Derived> |
| 5342 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5343 | unsigned NumElements, |
| 5344 | SourceLocation AttributeLoc) { |
| 5345 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5346 | NumElements, true); |
| 5347 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5348 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5349 | AttributeLoc); |
| 5350 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5351 | AttributeLoc); |
| 5352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5353 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5354 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5355 | QualType |
| 5356 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5357 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5358 | SourceLocation AttributeLoc) { |
| 5359 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5360 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5361 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5362 | template<typename Derived> |
| 5363 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5364 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5365 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5366 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5367 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5368 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5369 | Quals, |
| 5370 | getDerived().getBaseLocation(), |
| 5371 | getDerived().getBaseEntity()); |
| 5372 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5373 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5374 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5375 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5376 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5377 | } |
| 5378 | |
| 5379 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5380 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5381 | assert(D && "no decl found"); |
| 5382 | if (D->isInvalidDecl()) return QualType(); |
| 5383 | |
| 5384 | TypeDecl *Ty; |
| 5385 | if (isa<UsingDecl>(D)) { |
| 5386 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5387 | assert(Using->isTypeName() && |
| 5388 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5389 | |
| 5390 | // A valid resolved using typename decl points to exactly one type decl. |
| 5391 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5392 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5393 | |
| 5394 | } else { |
| 5395 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5396 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5397 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5398 | } |
| 5399 | |
| 5400 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5401 | } |
| 5402 | |
| 5403 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5404 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5405 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5406 | } |
| 5407 | |
| 5408 | template<typename Derived> |
| 5409 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5410 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5411 | } |
| 5412 | |
| 5413 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5414 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5415 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5416 | } |
| 5417 | |
| 5418 | template<typename Derived> |
| 5419 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5420 | TemplateName Template, |
| 5421 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5422 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5423 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5425 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5426 | template<typename Derived> |
| 5427 | NestedNameSpecifier * |
| 5428 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5429 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5430 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5431 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5432 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5433 | CXXScopeSpec SS; |
| 5434 | // FIXME: The source location information is all wrong. |
| 5435 | SS.setRange(Range); |
| 5436 | SS.setScopeRep(Prefix); |
| 5437 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5438 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5439 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5440 | ObjectType, |
| 5441 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5442 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | template<typename Derived> |
| 5446 | NestedNameSpecifier * |
| 5447 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5448 | SourceRange Range, |
| 5449 | NamespaceDecl *NS) { |
| 5450 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5451 | } |
| 5452 | |
| 5453 | template<typename Derived> |
| 5454 | NestedNameSpecifier * |
| 5455 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5456 | SourceRange Range, |
| 5457 | bool TemplateKW, |
| 5458 | QualType T) { |
| 5459 | if (T->isDependentType() || T->isRecordType() || |
| 5460 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5461 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5462 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5463 | T.getTypePtr()); |
| 5464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5466 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5467 | return 0; |
| 5468 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5470 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5471 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5472 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5473 | bool TemplateKW, |
| 5474 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5475 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5476 | Template); |
| 5477 | } |
| 5478 | |
| 5479 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5480 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5481 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5482 | const IdentifierInfo &II, |
| 5483 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5484 | CXXScopeSpec SS; |
| 5485 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5486 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5487 | UnqualifiedId Name; |
| 5488 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5489 | return getSema().ActOnDependentTemplateName( |
| 5490 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5491 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5492 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5493 | ObjectType.getAsOpaquePtr(), |
| 5494 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5495 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5496 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5497 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5498 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5499 | TemplateName |
| 5500 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5501 | OverloadedOperatorKind Operator, |
| 5502 | QualType ObjectType) { |
| 5503 | CXXScopeSpec SS; |
| 5504 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5505 | SS.setScopeRep(Qualifier); |
| 5506 | UnqualifiedId Name; |
| 5507 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5508 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5509 | Operator, SymbolLocations); |
| 5510 | return getSema().ActOnDependentTemplateName( |
| 5511 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5512 | SS, |
| 5513 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5514 | ObjectType.getAsOpaquePtr(), |
| 5515 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5516 | .template getAsVal<TemplateName>(); |
| 5517 | } |
| 5518 | |
| 5519 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5520 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5521 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5522 | SourceLocation OpLoc, |
| 5523 | ExprArg Callee, |
| 5524 | ExprArg First, |
| 5525 | ExprArg Second) { |
| 5526 | Expr *FirstExpr = (Expr *)First.get(); |
| 5527 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5528 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5529 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5531 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5532 | if (Op == OO_Subscript) { |
| 5533 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5534 | !SecondExpr->getType()->isOverloadableType()) |
| 5535 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5536 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5537 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5538 | } else if (Op == OO_Arrow) { |
| 5539 | // -> is never a builtin operation. |
| 5540 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5541 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5542 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5543 | // The argument is not of overloadable type, so try to create a |
| 5544 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5545 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5546 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5547 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5548 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5549 | } |
| 5550 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5551 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5552 | !SecondExpr->getType()->isOverloadableType()) { |
| 5553 | // Neither of the arguments is an overloadable type, so try to |
| 5554 | // create a built-in binary operation. |
| 5555 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5556 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5557 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5558 | if (Result.isInvalid()) |
| 5559 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5560 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5561 | First.release(); |
| 5562 | Second.release(); |
| 5563 | return move(Result); |
| 5564 | } |
| 5565 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5566 | |
| 5567 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | // used during overload resolution. |
| 5569 | Sema::FunctionSet Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5570 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5571 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5572 | assert(ULE->requiresADL()); |
| 5573 | |
| 5574 | // FIXME: Do we have to check |
| 5575 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5576 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5577 | E = ULE->decls_end(); I != E; ++I) |
| 5578 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5579 | } else { |
| 5580 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5581 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 5582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5584 | // Add any functions found via argument-dependent lookup. |
| 5585 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5586 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5587 | DeclarationName OpName |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5588 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | c057f42 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5589 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5590 | Functions); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5591 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5592 | // Create the overloaded operator invocation for unary operators. |
| 5593 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5595 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5596 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5597 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5598 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5599 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5600 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5601 | OpLoc, |
| 5602 | move(First), |
| 5603 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5604 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5605 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5606 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5607 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5608 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5609 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5610 | if (Result.isInvalid()) |
| 5611 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5612 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5613 | First.release(); |
| 5614 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5617 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5618 | } // end namespace clang |
| 5619 | |
| 5620 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |